I'm trying to use colormap to assign colors to lines on a plot. The data for each line is generated from a file, and the number of files imported/ lines plotted are variable each time. My code for this is:
d = uigetdir(pwd, 'Select a folder');
files = dir(fullfile(d, '*.txt'));
len = length(files);
for i = 1:len
a = files(i).name;
filename{i} = a;
path = [d,'\',a];
colour = round(random('unif',0,200,1,3))/255;
data = dlmread(path);
plot(data(:,1), data(:,2),'color',colour,'linewidth',2);
hold on;
end
hold off;
At the moment the colors of the lines are generated randomly, but I would really like to use colormap (jet(n))
so that the lines run from red to blue and are equally spaced in the spectrum.
However, as a different number of files are being imported each time, I don't know how much n will be. I have tried working colormap into my code, but I get errors each time.