Recreation function for figure
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2018-1-8
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?
回答(1 个)
Walter Roberson
2018-1-8
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 个评论
Walter Roberson
2018-1-9
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
2018-1-9
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Properties 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!