Skip to content
  • Search
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

ZMT zurich med tech

  1. Home
  2. Sim4Life
  3. Python API
  4. How can I read matlab export as a multi-dimensional array?

How can I read matlab export as a multi-dimensional array?

Scheduled Pinned Locked Moved Python API
2 Posts 2 Posters 1.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • pcrespoP Offline
    pcrespoP Offline
    pcrespo
    wrote on last edited by
    #1

    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.

    P.

    SylvainS 1 Reply Last reply
    1
    • pcrespoP pcrespo

      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.

      SylvainS Offline
      SylvainS Offline
      Sylvain
      ZMT
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0

      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
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Search