URL87
URL87

Reputation: 11032

Matlab - set plot Xaxis range according to the right argument

Having n vectors with same size (alson) held in v_1 , v_2 ..., v_n . I want to plot all of them together such that the Xaxis range will be 1..n and Yaxis value of each vector would be as its element according to X value .

Something like - plot(1:n,v_1,v_2,...,v_n)

Edit:

Fixed as @Phonon suggested .

How could I obtain the above ?

Upvotes: 0

Views: 227

Answers (1)

Ryan J. Smith
Ryan J. Smith

Reputation: 1140

You're pretty much on the right track already.

Assuming all your v_1, ... v_n are the same length and are each row vectors:

plot(1:m, [v_1; v_2; ... v_n]);

You could also plot them one at a time via:

figure;
plot(1:m, v_1);
hold on;
plot(1:m, v_2);
plot(1:m, v_3);
...
plot(1:m, v_n);

This second approach will ultimately give you more control over the attributes of each line in your plot.

If you need to change the limits of your x axis later, you can do this through the xlim([]) function or the set(axHandle,'XLim',[lowerLim, upperLim]) command.

Upvotes: 1

Related Questions