Please login with a confirmed email address before reporting spam
Posted:
5 years ago
Dec 19, 2019, 7:56 p.m. EST
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
Dec 20, 2019, 6:04 a.m. EST
Updated:
5 years ago
Dec 20, 2019, 6:05 a.m. EST
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
Dec 20, 2019, 3:20 p.m. EST
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
Jan 13, 2020, 9:09 a.m. EST
Updated:
5 years ago
Jan 13, 2020, 9:33 a.m. EST
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).