How do I assign a matrix column as my x or y values so that can plot them?

22 Ansichten (letzte 30 Tage)
aforden
aforden am 30 Mär. 2013
I'm not having any errors I just honestly don't know the commands. Thanks!

Antworten (2)

Walter Roberson
Walter Roberson am 30 Mär. 2013
x = YourMatrix(:, TheColumnNumber);
For example,
data = rand(64, 15);
x = data(:,11); %column 11
y = data(:,3);
plot(x,y);

Ahmed A. Selman
Ahmed A. Selman am 30 Mär. 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.

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by