How can I read matlab export as a multi-dimensional array?
-
I have exported the E-field resulting from a simulation into a matlab file (call it myresult.mat). For this, I have created a pipeline that gets the fields from a simulation and then I have attached an exporter.
When I load myresult.mat in matlab I get the following variables:
- Axis0, Axis1, Axis2 with shape1x11 values per axis. These are the Cartesian grid axis
- Snapshot0 with shape 1000,3. These are the 3 components of my field at the cell center of the Cartesian grid
I would like to reshape my flat list of values (i.e. Snapshot0) into a 4d array such that each dimension represents a component and the spatial axis, i.e. Snapshot0[c,i,j,k] where c is an index to the field component and i,j,k are indices to the discretization of space.
-
I have exported the E-field resulting from a simulation into a matlab file (call it myresult.mat). For this, I have created a pipeline that gets the fields from a simulation and then I have attached an exporter.
When I load myresult.mat in matlab I get the following variables:
- Axis0, Axis1, Axis2 with shape1x11 values per axis. These are the Cartesian grid axis
- Snapshot0 with shape 1000,3. These are the 3 components of my field at the cell center of the Cartesian grid
I would like to reshape my flat list of values (i.e. Snapshot0) into a 4d array such that each dimension represents a component and the spatial axis, i.e. Snapshot0[c,i,j,k] where c is an index to the field component and i,j,k are indices to the discretization of space.
In Matlab, you can reshape the Snapshot0 quantity in the following way.
- For cell-centered data with 3 components (e.g. Electric field E(x,y,z)):
E = reshape(Snapshot0, [length(Axis0)-1, length(Axis1)-1, length(Axis2)-1, 3)which you can then use as:
E[i,j,k,c]where c is an index to the field component and i,j,k are indices to the discretization of space.
- For point data with 1 component (e.g. Vector potential V(x,y,z)):
V = reshape(Snapshot0, [length(Axis0), length(Axis1), length(Axis2))which you can then use as:
V[i,j,k]where i,j,k are indices to the discretization of space.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login