How to set a graph legend based off user inputted values?
이전 댓글 표시
I'm trying to display a set of graphs based on generated data from earlier in the code. I'd like to be able to view the graphs for different time steps throughout which the user can set. There are about 500 time values from 0s to 5s with a step of 0.01s. How can I set the legend of the graph to update based on the values the user input?
prompt = {'First Time','Second Time','Third Time','Fourth Time'...
'Fifth Time'};
name = ('Enter time (s) values to compare data');
defaultanswer = {'0.1','0.2','0.3','0.4','0.5'};
N = 80;
graph_time = inputdlg(prompt,name,[1 N],defaultanswer);
graph_time = str2double(graph_time);
% Multiple the user inputted values by 100 to align with stored values %
graph_time = graph_time * 100;
hold on
plot (lambda,output(graph_time(1,:),:))
plot (lambda,output(graph_time(2,:),:))
plot (lambda,output(graph_time(3,:),:))
plot (lambda,output(graph_time(4,:),:))
plot (lambda,output(graph_time(5,:),:))
hold off
xlabel('Wavelength (\mum)')
ylabel('Output')
legend({'t = 0.1s','t = 0.2s','t = 0.3s','t = 0.4s','t = 0.5s'})
if (variable == 1)
title('Title 1')
elseif (variable == 2)
title('Title 2')
end
Thank you in advance!
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
