Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

Matlab livelink data from mphplot

Please login with a confirmed email address before reporting spam

I understand that the plot data is contained in an object given to me by the function mphplot(model,'pg1') How do I save that plot using only the command line and not the GUI? How do I access the plot data in that struct object?


4 Replies Last Post 13 janv. 2020, 09:09 UTC−5

Please login with a confirmed email address before reporting spam

Posted: 5 years ago 19 déc. 2019, 19:56 UTC−5

Please refer to the Livelink for Matlab User's Guide. More information about the mphplot function can be found.

Best,

Songcai

Please refer to the Livelink for Matlab User's Guide. More information about the mphplot function can be found. Best, Songcai

Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 5 years ago 20 déc. 2019, 06:04 UTC−5
Updated: 5 years ago 20 déc. 2019, 06:05 UTC−5

You get the data using this command:

pd = mphplot(model,'pg1')

pd is now a regular Matlab variable that you can inspect, save for later (using the save command) or use for plotting:

mphplot(pd)

The data is a regular Matlab cell array that contains structs so you can view the data by doing

>> pd{1}{1}

ans = 

struct with fields:

             p: [3×2800 single]
             t: [2×2100 int32]
           rgb: [3×1 double]
          type: 'line'
      plottype: 'PlotGroup3D'
           tag: 'pg1'
preserveaspect: 'on'
         title: 'Multislice: Electric potential (V)'
-------------------
Lars Gregersen
Comsol Denmark
You get the data using this command: pd = mphplot(model,'pg1') pd is now a regular Matlab variable that you can inspect, save for later (using the save command) or use for plotting: mphplot(pd) The data is a regular Matlab cell array that contains structs so you can view the data by doing >> pd{1}{1} ans = struct with fields: p: [3×2800 single] t: [2×2100 int32] rgb: [3×1 double] type: 'line' plottype: 'PlotGroup3D' tag: 'pg1' preserveaspect: 'on' title: 'Multislice: Electric potential (V)'

Please login with a confirmed email address before reporting spam

Posted: 5 years ago 20 déc. 2019, 15:20 UTC−5

Maybe my misunderstanding is not with COMSOL's Matlab functions, but with MATLAB itself. I tried saveas with various arguments, save with various arguments (even though that's not what I wanted), savefig...

What ended up ACTUALLY being the answer (for those who google this later), is that there is somehow a difference between an object and a struct and a "cell."

The key to saving the figure is to turn "pd" into another form of the above handles by simply saying,

fig_handle = gcf

And the gcf works how I thought pd should work:

saveas(fig_handle, 'thenameofthefile.png')

And the answer to my other question, is that the addresses are a little weird, but you can get the addresses of the data by double-clicking the object in your workspace, and then click on the various "cells" in the window that pops up. The address on the top of the window is the same as the address of the stuff you're looking at in the window, to do things like:

plot3(pd{1,2}{1,1}.p(1,:),pd{1,2}{1,1}.p(2,:),pd{1,2}{1,1}.d)

Maybe my misunderstanding is not with COMSOL's Matlab functions, but with MATLAB itself. I tried saveas with various arguments, save with various arguments (even though that's not what I wanted), savefig... What ended up ACTUALLY being the answer (for those who google this later), is that there is somehow a difference between an object and a struct and a "cell." The key to saving the figure is to turn "pd" into another form of the above handles by simply saying, ## fig_handle = gcf And the gcf works how I thought pd should work: ## saveas(fig_handle, 'thenameofthefile.png') And the answer to my other question, is that the addresses are a little weird, but you can get the addresses of the data by double-clicking the object in your workspace, and then click on the various "cells" in the window that pops up. The address on the top of the window is the same as the address of the stuff you're looking at in the window, to do things like: plot3(pd{1,2}{1,1}.p(1,:),pd{1,2}{1,1}.p(2,:),pd{1,2}{1,1}.d)

Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 5 years ago 13 janv. 2020, 09:09 UTC−5
Updated: 5 years ago 13 janv. 2020, 09:33 UTC−5

Hi Marie

Yes, you're right.

When you use

h=plot(x,y)

then the h that is returned is a handle to the graphics that is produced in a figure on screen. A handle can either be an object or just a number (that Matlab internally converts into an object when needed).

When using

pd=mphplot(model, 'pg1')

the pd that is returned is a (complicated) cell array that contains the data that are required to reproduce the data. We didn't find it very useful to return handles from mhplot since even a simple plot of Comsol results usually contains a lot of different objects (and you can always get the handles directly from the figure, if you need them).

-------------------
Lars Gregersen
Comsol Denmark
Hi Marie Yes, you're right. When you use h=plot(x,y) then the h that is returned is a handle to the graphics that is produced in a figure on screen. A handle can either be an object or just a number (that Matlab internally converts into an object when needed). When using pd=mphplot(model, 'pg1') the pd that is returned is a (complicated) cell array that contains the data that are required to reproduce the data. We didn't find it very useful to return handles from mhplot since even a simple plot of Comsol results usually contains a lot of different objects (and you can always get the handles directly from the figure, if you need them).

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.