【发布时间】:2013-10-17 09:37:08
【问题描述】:
我觉得我已经阅读/尝试了所有关于此的在线建议 - 可能错过了明显的!在 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
【问题讨论】:
-
你能提供一个最小的例子吗?
标签: matlab loops colors legend