Adding several plots to one specific (not current) figure
조회 수: 11 (최근 30일)
이전 댓글 표시
The code below is simplified. But I struggle to find out how I can update a specific figure (maybe by the specific name?).
I want to add some x,y plots to one specific figure.
for p=1:length(vector)
%above this pointthere are several plots and many figures made both inside this for loop and outside
figure('Name',figurnavn1)
hold on
plot(x,y)
end
end
%below this point there are several plots and many figures made both inside this for loop and outside
댓글 수: 0
채택된 답변
Image Analyst
2022년 8월 31일
Get the handle when you create that one special figure. Then pass it to figure()
hSpecial = figure('Name', 'My Special Figure');
Then in the for loop:
figure(hSpecial); % Switch to this specific figure.
댓글 수: 5
Image Analyst
2022년 9월 1일
You didn't do what I said. You did
hSpecial=figure('Name',figurnavn,'NumberTitle','off');
%set(0,'CurrentFigure',hSpecial);
figure(hSpecial)
plot(prosent,varighet_yakse_fordeling)
OK, let's look what this does. First you call figure() and give it a certain name and get the handle to the figure back in hSpecial. This will create a new figure window.
Then you call figure(hSpecial) which switches to that figure, but since you had just created it, there was no need to switch to it -- it already was the current figure so no switching was needed. And then you plot to it.
But, unless I missed something, that's the only time you deal with hSpecial. You had said that you were creating and plotting to other figures and then wanted to switch back to hSpecial, like
hSpecial = figure('Name', figurnavn, 'NumberTitle', 'off');
plot(prosent,varighet_yakse_fordeling)
h1 = figure('Name', 'First figure'); % Create a new figure.
plot(1:10);
h2 = figure('Name', 'Second figure'); % Create a new figure.
plot(2:33);
% Now switch back to the already-created special figure.
figure(hSpecial); % Pass it the HANDLE, not a name.
% Plot to the special figure.
plot(3:44);
So the above code will let you plot to other figures but then when you want, you can switch back to the special figure and plot to it.
추가 답변 (2개)
Ingvald Bårdsen
2022년 8월 31일
댓글 수: 2
Mathieu NOE
2022년 8월 31일
hello again
wonder if there is another way to solve your problem
maybe it's a bit the hammer solution but why not put your data in a structure (or simply an array if that can suffice) and each time you add new data to the previous set , simply plot again the whole thing
sure not the most elegant manner but...
참고 항목
카테고리
Help Center 및 File Exchange에서 Axis Labels에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!