How do I assign a matrix column as my x or y values so that can plot them?
20 views (last 30 days)
Show older comments
I'm not having any errors I just honestly don't know the commands. Thanks!
0 Comments
Answers (2)
Walter Roberson
on 30 Mar 2013
x = YourMatrix(:, TheColumnNumber);
For example,
data = rand(64, 15);
x = data(:,11); %column 11
y = data(:,3);
plot(x,y);
0 Comments
Ahmed A. Selman
on 30 Mar 2013
Use the basic matrix notation, the colon operator is very helpful in such cases. Example:
y=magic(5)
y =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
To plot the first row only:
plot(y(1,:))
To plot rows from the first to the third:
plot(y(1:3,:))
To plot columns 1 and 4:
plot(y(:,[1,4])) ... etc.
If you want to plot x and y axes specifically, use plot(x,y). As in:
x=-pi:0.1:pi;
y=sin(x);
plot(y) % this plots from 0 to 2 pi on the x-axis
plot(x,y) % this plots from -pi to pi.. etc.
0 Comments
See Also
Categories
Find more on Line Plots 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!