我觉得我已经阅读/尝试了每一个关于此的在线建议 - 也许错过了显而易见的事情!在Matlab R2013a中,我正在绘制一个循环中的多行(每次读取的行数是可变的),然后添加一个图例,其中从列表中读取系列名称。图例上的线条颜色与图表上的线条颜色不匹配。
我试过彩色地图,得到&设置命令,将图例放在循环内外,为图例创建单独的循环等等......请帮忙!代码的相关部分如下:
%% getting the data....
for i=1:length(files); % for each file in the folder
FileName = files(i,1).name; % extract the filename
calfile = files(i,1).name; % lists all filenames for metadata
a = length(calfile);
fn(i,1:a) = calfile;
fid_data(i) = fopen(files(i,1).name,'r'); % open that file
data = csvread(FileName,0,1,[0 1 15 30]); %
diam(i,:) = data(9,:); % puts each channel center diameter into array
diamerr(i,:) = data(10,:); % channel centre error
end
x = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30];
%% Plotting data
h = (figure('name','campaign summary','numbertitle','off'));
set(gca, 'box','on')
for r = 1:i
plot(x,diam(r,:)); % plots diameters for each flight
hold all
errorbar(diam(r,:), diamerr(r,:)); % plots error bars for each flight diameters
end
legend(fn(:,:),'location', 'northwest'); % legend derived from filename list
set(legend,'Interpreter','none'); % stops the underscore from making text subscript
答案 0 :(得分:0)
您不需要plot
和errorbar
。 errorbar
函数正在绘制先前在plot
循环中绘制的线。然后将图例应用于这些隐藏线以及可见线。摆脱plot
并使用errorbar(x, diam(r,:), diamerr(r,:))
代替。