Recreation function for figure

1 Ansicht (letzte 30 Tage)
Maniraj M
Maniraj M am 8 Jan. 2018
Kommentiert: Walter Roberson am 9 Jan. 2018
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
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
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.

Kategorien

Mehr zu Graphics Object Properties finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by