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?


3 Replies Last Post 20 dec. 2019 20:20 WET

Please login with a confirmed email address before reporting spam

Posted: 3 weeks ago 20 dec. 2019 00:56 WET

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: 3 weeks ago 20 dec. 2019 11:04 WET
Updated: 3 weeks ago 20 dec. 2019 11:05 WET

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: 3 weeks ago 20 dec. 2019 20:20 WET

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)

Reply

Please read the discussion forum rules before posting.

Please log in to post a reply.

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.