user2045143
user2045143

Reputation: 249

Plotting in Matlab by splitting up matrices

I have two vectors xline and yline with 63 values in each, which I have derived from previous calculations. Out of these 63 values, The first 21 values of xline represent x co-ordinates of a line and similarly for yline they are y co-ordinates. The next 21 values are for a second line and so on.

How do I go about splitting these 63 values into 3 separate lines and plot them on an xy graph in Matlab?

Upvotes: 1

Views: 132

Answers (1)

Floris
Floris

Reputation: 46435

plot(reshape(xline,[21 3])', reshape(yline,[21 3])') should do the trick . Possibly you don't need to transpose both - I can never remember how Matlab likes its multi-line plots.

This is because Matlab stores matrices row-first: so when you reshape the array, you create multiple rows (becomes columns) and the plot command figures out what you want from there.

Upvotes: 3

Related Questions