How do I plot from excel different columns file?

15 次查看(过去 30 天)
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.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by