how to plot exel data by loop

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, ...

2 件のコメント

Walter Roberson
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 ?
a.s
a.s 2022 年 1 月 26 日
Column D is for X data and column E is for Y data, and I want all data for number 1 to be displayed in one color (for example, red) and all data for number 2 to be displayed in another color.

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2022 年 1 月 26 日

0 投票

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 件のコメント

a.s
a.s 2022 年 2 月 6 日
thanks a lot

サインインしてコメントする。

その他の回答 (1 件)

Biraj Khanal
Biraj Khanal 2022 年 1 月 26 日

0 投票

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.

1 件のコメント

a.s
a.s 2022 年 2 月 14 日
thank you so much but its not work

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeDevelop Apps Using App Designer についてさらに検索

質問済み:

a.s
2022 年 1 月 26 日

コメント済み:

a.s
2022 年 2 月 14 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by