How do I plot from excel different columns file?

14 ビュー (過去 30 日間)
Karl-JR
Karl-JR 2023 年 1 月 8 日
コメント済み: Karl-JR 2023 年 1 月 8 日
Hello everyone. i am completely new to Matlab and I have a problem with an exercise in my practice book. I have a file in excel looking like this:
a b c d e f g h
1 6 7 4 3 3 4 7
2 6 6 6 6 6 6 6
3 4 3 7 9 3 6 7
4 9 5 3 1 2 2 6
5 7 9 4 7 3 3 2
6 4 6 7 8 9 5 6
I had no problem importing it. Now i want to visualize the column "c","f" and "h" it in a graph with column "a" being the x-axis. I tried stuff like this
[numbers, txt, raw] = xlsread("filename");
colc = numbers(:, 3);
colf = numbers(:, 6);
colh = numbers(:, 8);
But now i am getting nowhere. How do i continue? I´m trying for around 2 hours at this point😅

採用された回答

John D'Errico
John D'Errico 2023 年 1 月 8 日
編集済み: John D'Errico 2023 年 1 月 8 日
You were ALMOST there. Literally, almost. You need the x axis variable. Here is your array:
numbers = [1 6 7 4 3 3 4 7;2 6 6 6 6 6 6 6;...
3 4 3 7 9 3 6 7;4 9 5 3 1 2 2 6;...
5 7 9 4 7 3 3 2;6 4 6 7 8 9 5 6];
Now extract the columns you care about.
cola = numbers(:,1);
colc = numbers(:, 3);
colf = numbers(:, 6);
colh = numbers(:, 8);
So you pretty much had that. I just added the cola. Now call plot.
plot(cola,[colc,colf,colh],'-o')
legend('C','f','h')
So three curves, although they overlap at the first few points, so you might not see them as different.
  3 件のコメント
John D'Errico
John D'Errico 2023 年 1 月 8 日
編集済み: John D'Errico 2023 年 1 月 8 日
I'm not absolutely positive what you mean by define, since a plot is just a picture. I think you mean to provide axis labels. You can also have a title label on top of the plot.
plot(1:5,rand(1,5),'o-')
xlabel 'Quality'
ylabel 'Quantity'
title 'Furlongs per fortnight' % I'm not very creative about a good title. sorry.
And in three dimensions, there is zlabel, which does not apply here.
Karl-JR
Karl-JR 2023 年 1 月 8 日
Wow, you helped me a lot. Thank you🙏😁

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by