Formatting Legend Entries from a Double in a For Loop
5 ビュー (過去 30 日間)
古いコメントを表示
Camille Woicekowski
2020 年 8 月 18 日
コメント済み: Camille Woicekowski
2020 年 8 月 18 日
I'm struggling to make the legend on the graph to display properly.
I want to value of sensor to display with the corresponding line plotted from soil. ( sensor ranges from 12 to 1)
sensor = fliplr(1:1:size(soil,2));
Putting sensor directly into the legend argument gives me the error message "improper type of type of double cannot be used with this function"
I tried
figure();
cc=colorcube(size(soil,2));
j=0;
for i = 1:size(soil,2)
j=j+1;
p=plot(date_soil,soil(:,i), "Color",cc(i,:));
hold on
datetick('x','mmm-dd HH:MM',"keeplimits","keepticks");
strr(j,:) = sprintf('%i',sensor(1,i));
end
hold on
leg=legend(strr);
Which gives me the error "unable to preform assignment because the size of the right side is 1x1 and the size of the left side is 1x2"
I tried different formatSpecs for sprintf and nothing has worked.
How can I get the legend to display the proper values?
0 件のコメント
採用された回答
Joel Van Sickel
2020 年 8 月 18 日
Hello Camille,
I made some assumptions about how soil and date_soil were formatted, but does this script get close to what you are looking for? (it plots the first line white on white so that is not ideal but easily fixed by modifying cc)
soil = [1 2 3 4;2 2 3 4; 3 2 3 4; 4 5 3 4; 5 5 3 4];
date_soil = 1:5;
n = size(soil,2);
sensor = fliplr(1:1:n);
figure();
cc=colorcube(n+1);
strr = cell(n,1);
for i = 1:n
p=plot(date_soil,soil(:,i), "Color",cc(i,:));
hold on
datetick('x','mmm-dd HH:MM',"keeplimits","keepticks");
strr{i,:} = num2str(sensor(i));
end
hold on
leg=legend(strr);
Regards,
Joel
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Distribution Plots についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!