How do I assign a matrix column as my x or y values so that can plot them?
20 次查看(过去 30 天)
显示 更早的评论
I'm not having any errors I just honestly don't know the commands. Thanks!
0 个评论
回答(2 个)
Walter Roberson
2013-3-30
x = YourMatrix(:, TheColumnNumber);
For example,
data = rand(64, 15);
x = data(:,11); %column 11
y = data(:,3);
plot(x,y);
0 个评论
Ahmed A. Selman
2013-3-30
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!