I am holding onto a scatter plot and adding data to it through a for loop. For each data set, I would like to label it in the legend but I am running into some problems.
57 次查看(过去 30 天)
显示 更早的评论
Below is the line of code I am using. As you can see I am running a for loop where each time it adds a different data set to a scatter plot (this part is working beautifully), but I can't seem to figure out how to change the display name for each data added--obviously this doesn't work and I feel like the j would be useful, but as my comment suggests, it hasn't been so far.
for j=1:height(Fe4plsr),
figure(1)
hold on
B=table2array(A4plsr(j, 2:209));
scatter(A, B, "DisplayName", "Fe")
%cant add j outside of "" to know which, cant add j inside "" because it wouldn't change
xlabel('Wavelengths(nm)')
ylabel('Frequency')
A4corr(j, :)= [B];
end
0 个评论
采纳的回答
Star Strider
2021-6-25
I have no idea what the matrices are or what the different display names would be.
One approach would be to get the variable names of the table you want to plot (I have no idea how to eimulate that with your code without your data) and then use that as the display name
Table1 = array2table(rand(10,3), 'VariableNames',{'Fe','Co','Al'})
VN = Table1.Properties.VariableNames;
figure(1)
hold on
for j=1:3,
scatter((1:10), Table1{:,j}, "DisplayName", VN{j})
end
hold off
legend('Location','best')
Another option of course is to simply use the ‘VN’ cell array in this example as a legend argument.
.
2 个评论
更多回答(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!