How to set a graph legend based off user inputted values?
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Dyuman Joshi
2023 年 3 月 9 日
編集済み: Dyuman Joshi
2023 年 3 月 9 日
%Sample output (from user input)
out = {'0.2';'0.15';'0.36';'0.4';'0.07'};
num=str2double(out);
%String arrays corresponding to each value
str=compose('t = %0.02fs', num)
%Sample data
x=0:0.1:10;
y=sin(x);
%5 Random plots
plot(x,y,x,y.^2,x,x+y,x,x-y,x,x.*y)
%legend
legend(str)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!