How do I plot from excel different columns file?

13 views (last 30 days)
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😅

Accepted Answer

John D'Errico
John D'Errico on 8 Jan 2023
Edited: John D'Errico on 8 Jan 2023
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 Comments
John D'Errico
John D'Errico on 8 Jan 2023
Edited: John D'Errico on 8 Jan 2023
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 on 8 Jan 2023
Wow, you helped me a lot. Thank you🙏😁

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!