Multiple plots in the same figure
显示 更早的评论
I have a complex function:
function [FinalResults,Plotting]=Dicom_Reading(Variables)
Plotting=gobjects(5,1);% declare the graphics object
figure
hold on
.
.
.
% other commands
.
.
.
for n=1:5
% other commands
Plotting(n)=plot(x,y,chosencolor,'DisplayName',material)
legend(Plotting(1))% I do this get only 1 legend as they are all the same
end
x and y are different each time.
chosencolor is a string choosing the color.
material is a string with what I would like to have in the legend.
I believe the function is set up correctly as I do indeed get a figure with only 1 legend and 5 curves all of the same color.
I would like to run the function 3 different times for different variables and afterwards combine all the plots in the same graph so that I can compare them.
I expected that
[FinalResults1,Plotting1]=Dicom_Reading(Variables1)
[FinalResults2,Plotting2]=Dicom_Reading(Variables2)
[FinalResults3,Plotting3]=Dicom_Reading(Variables3)
hold on
Plotting1;
Plotting2;
Plotting3;
would work but it is not doing anything, I still get 3 different figures.
Maybe it has something to do with the fact that Plotting1, Plotting2 and Plotting 3 return as 5x1 Line arrays instead of plots?
I also tried changing the code in the function itself by switching the place of the hold command to
for n=1:5
% other commands
hold on
Plotting(n)=plot(x,y,chosencolor,'DisplayName',material)
legend(Plotting(1))% I do this get only 1 legend as they are all the same
end
This does in fact allow me to get all the 15 plots in the same graph but now I only get the legend for the 3rd plot.
I would like to know if there is a solution to this, either combining the 3 plots in the first case or getting all 3 legends in the second case.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!