Recreation function for figure

Let us assume, we have created a figure numbered as 1. After creation there are finite changes made manually in the figure window, like change legend position, colorbar location etc. Then, are there any way to covert the complete figure with all its changes to recreation function with figure1. This means I am try to make a single code that can be run to create a figure and then make changes, and update same function by new details from updated figure.
This way, it would be easier to get the changes done using GUI and store the changes as code for future recreation.
At the moment, if I use Generate code in File menu, but it put very general code without details of actual data present in figure window.
Any suggestion !

2 Kommentare

Walter Roberson
Walter Roberson am 8 Jan. 2018
Were you the one that posted a similar question but in which you gave specific code involving fit(), and your difficulty was that the generated code needed four inputs but you only had two inputs?
Maniraj M
Maniraj M am 9 Jan. 2018
No. It is my second post in whole matlab forum. I am not to that level !

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 8 Jan. 2018

0 Stimmen

Not really, no. Generate Code knows that you got data somewhere but it does not know anything about where it came from. For example your code might have been,
X = xlsread('SomeFile.xls');
Y1 = sin(X);
Y2 = Y1.^2;
plot(X, Y1, 'g', X, Y2, 'b')
but all Generate Code can know is that there are two X vectors and two Y vectors that come from somewhere : it must assume that the fact that the two X vectors were the same for the lines was an accident, and it must assume that any relationship it might possibly calculate between the two Y vectors is an accident.
So where you might be hoping for generated code that was like
function plot_for_me(filename)
X = xlsread(filename);
Y1 = sin(X);
Y2 = Y1.^2;
plot(X, Y1, 'g', X, Y2, 'b');
there is no reasonable way that Generate Code could come up with anything other than
function plot_for_me(X1, Y1, X2, Y2)
plot(X1, Y1, 'g', X2, Y2, 'b');
Likewise, if you had happened to use surfc() on an input matrix, all that Generate Code can know is that there is a contour plot and a surface on the same axes, and it has to assume that they are unrelated, because you might have happened to call contour() and surf() yourself in combination that came with the same form as surfc() generates.
So, No, Generate Code cannot re-create entire plots: it can only re-create plots under the assumption that no part of the graphics is related to any other part of the graphics and so that everything has to be passed in.
It is unlikely, for example, to detect that the graphic is a bode plot and that the desired input would be the dynamic system: it would just know that a bunch of lines had to go up with particular colors and widths and so on.

3 Kommentare

Maniraj M
Maniraj M am 9 Jan. 2018
Bearbeitet: Maniraj M am 9 Jan. 2018
Well, Thanks a lot for your interest. You may be partially correct. I do not expect to generate a code with all the way back to how X,Y1, Y2 are generated. Rather it should just write that there is X (being called X=x-data), Y1 (being called Y1=y1-data) and Y2 (being called Y2=y2-data). I have to make sure before running the recreation function that both x-, y1- and y2-data are available in workspace. Given such a condition, I would expect that we can make recreation script. May be with gcf, I am trying but not succeeded. Since Matlab is completely code based I blindly expected such option and thought that I am not aware of it.
By the way, if you say Matlab does not even know what kind of plotting function used in a given figure, that is something not digestible and highly disappointing ! It seems to store lot of information, may be somewhere (in gcf, gca etc) it is hidden I suppose.
Walter Roberson
Walter Roberson am 9 Jan. 2018
MATLAB generates graphics by "primitives". It does not have a different type of graphics object for every call that creates graphics: graphics calls like surfc use combinations of existing graphics calls. But Generate Figure only knows what the result is, not what calls were made.
Walter Roberson
Walter Roberson am 9 Jan. 2018
The Generate Code option creates code assuming that it is passed in all appropriate data -- which turns out not to be as useful as one might hope if the original data was re-used or put through calculations to generate the plots.

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 8 Jan. 2018

Kommentiert:

am 9 Jan. 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by