how to plot exel data by loop
4 次查看(过去 30 天)
显示 更早的评论
I have an Excel file that has 381 rows, and as shown in the figure in column F, I want the numbers 1 to be drawn together and the numbers 2 to be drawn together, ...![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/873990/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/873990/image.png)
2 个评论
Walter Roberson
2022-1-26
You have six numeric columns in addition to the grouping column. How do you want each segment to be drawn ?
采纳的回答
Walter Roberson
2022-1-26
filename = 'TheFile.xlsx';
T = readtable(filename);
[G, uids] = findgroups(T{:,6});
hold on
h = splitapply(@(X,Y) plot(X, Y), T{:,4}, T{:,5}, G);
hold off
xlim auto; ylim auto
group_names = "Group " + string(uids(:));
legend(h, group_names);
更多回答(1 个)
Biraj Khanal
2022-1-26
I am still learning and would do this:
T=readtable('filename');
D1=[];
E1=[];
D2= []; E2=[];
for i = 1: height(T)
if T.F (i) == 1
D1(end+1) = T.D(i);
E1(end+1) = T.E(i);
elseif T.F(i) == 2
D2(end+1) = T.D(i);
E2(end+1) = T.E(i);
end
end
figure
plot(D1,E1)
hold on
plot (D2,E2)
I am sure there is a more efficient way to do it.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 View and Analyze Simulation Results 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!