Plot a table and generate legend from values from the table
14 次查看(过去 30 天)
显示 更早的评论
I have following table (you can find the file in the attachment):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/726859/image.jpeg)
I am reading this table in MATLAB and creating a plot of three lines (I am interested in the lines for the stress ratio "-1") as follows:
imported = readtable('raw_data.xlsx');
plot([imported{1, {'a','c'}}], imported{1,{'b', 'd'}},...
[imported{3, {'a','c'}}], imported{3,{'b', 'd'}},...
[imported{4, {'a','c'}}], imported{4,{'b', 'd'}});
Then I recieve such result:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/726864/image.png)
While plotting I know that the ''-1" stress ratio data are in the lines 1, 3 and 4 in the table "imported". But what if I don't know where are the lines with stress ratio "-1" and I have, for example, stress ratios "1" and "0". Moreover, let es assume I have more then 1000 data.
I would like to have a script be created that founds data for "-1" stress ratio and adds a following legend:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/726869/image.png)
0 个评论
采纳的回答
Star Strider
2021-9-1
Try this —
imported = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/726854/raw_data.xlsx');
lgdtbl = imported(imported{:,5}<0,[6 7]);
lgdvn = join(lgdtbl.Properties.VariableNames, ' ');
lgdnum = compose('%2d %2d', table2array(lgdtbl));
figure
plot([imported{1, {'a','c'}}], imported{1,{'b', 'd'}},...
[imported{3, {'a','c'}}], imported{3,{'b', 'd'}},...
[imported{4, {'a','c'}}], imported{4,{'b', 'd'}});
hlgd = legend(lgdnum, 'Location','S');
title(hlgd, lgdvn)
This is likely as close as it is possible to get to what you want.
Experiment to get different results.
.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Stress and Strain 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!