How do I plot from excel different columns file?
13 views (last 30 days)
Show older comments
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😅
0 Comments
Accepted Answer
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
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.
More Answers (0)
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
