Plotting an unknown number of lines in different colours

Hi all, First post here, so please do bear with me!
Right, I'm running some simulations that export to text files containing tables of data. Only the first and 3rd columns of data are useful. Each simulation has a seperate text file and they are named/ordered with a corresponding number.
So I've got a matlab m-file to import the data and sort it out, so that only the useful columns are stored.
Basically, what I want is a plot of the error versus iteration number. At the moments there's six files, so the table I finish with is 12 colums wide:
x1, y1, x2, y2......x12, y12 (we'll call this table results for now)
Originally I put it in a for loop:
for i = 1:6
figure(1)
hold on
plot(results(:,((2*i)-1)), results(:,(2*i)))
end
but the problem with this, is that it makes all the lines the same colour. I want to have it automated, because the number of files will vary and currently the m-file identifies/counts how many result files there are...
Any ideas?

 Accepted Answer

I suggest to store x and y in different matrices and to call:
plot(x,y)
Or with your data:
results = rand(20,10);
sz = size(results);
idx = 2*(1:sz(2)/2)-1;
plot(results(:,idx),results(:,idx+1))
Oleg

1 Comment

Thanks for your response, maybe I was a bit impulsive in my posting of the question, didn't realise the solution was quite as simple as it is. No need for a for loop etc, just plot the entire matrices.
Thanks

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!