필터 지우기
필터 지우기

Adding Legends to multiple lines in an x-y plot of data imported from Excel sheets in MATLAB ?

조회 수: 1 (최근 30일)
Hi, I have the following code:
[~,sheets] = xlsfinfo('C:\Users\Bilal Ahmad\Desktop\Complete Simulations\Microphone Array 1_AllSources\AllSource_MicArr1.xlsx');
for i = 1:length(sheets)
data{i} = xlsread('C:\Users\Bilal Ahmad\Desktop\Complete Simulations\Microphone Array 1_AllSources\AllSource_MicArr1.xlsx',sheets{i},'A4:T6');
d = data{i}(:,7);
tau_g = data{i}(:,9);
plot(d,tau_g,'-x');
hold all
grid on
xlabel('distance d b/w mic pairs[cm]');
ylabel('\tau_g_r_o_u_n_d');
title('Relationship between \tau ground and distance between Mic Pairs for Array 1');
end
when i run this code. i get a following plot
Now, As it is clear in this plot that i am getting data from 16 different sheets that belongs to 16 different sources. My problem is I want to show labels to each 16 different lines so that i come to know which line belong to which sheet of data? Can anybody help me in this regard. Thank you

채택된 답변

madhan ravi
madhan ravi 2018년 10월 8일
편집: madhan ravi 2018년 10월 8일
Legend=cell(16,1)
for iter=1:16
Legend{iter}=strcat('sheet', num2str(iter));
end
legend(Legend)
  댓글 수: 5
Ahmad Bilal
Ahmad Bilal 2018년 10월 8일
My question is how can i fit this code in the above mentioned code because when I tried it shows an error : index exceeds matrix dimensions
madhan ravi
madhan ravi 2018년 10월 8일
편집: madhan ravi 2018년 10월 8일
Which line shows error , your question is vague.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Ahmad Bilal
Ahmad Bilal 2018년 10월 8일
Hi this is my now updated code.
[~,sheets] = xlsfinfo('C:\Users\Bilal Ahmad\Desktop\Complete Simulations\Microphone Array 3_AllSources\AllSrc_MicArray3.xlsx');
for i = 1:length(sheets)
data{i} = xlsread('C:\Users\Bilal Ahmad\Desktop\Complete Simulations\Microphone Array 3_AllSources\AllSrc_MicArray3.xlsx',sheets{i},'A4:T8');
d = data{i}(:,7);
tau_g = data{i}(:,9);
hold all
grid on
Legend = cell(16,1);
for iter = 1:16
Legend{iter} = strcat('source', num2str(iter));
end
legend(Legend)
lineColor = {'k', 'r', 'b', 'm'};
linestyle = {'-'; '--'; ':'; '-.'};
for j = 1:4
options = {'color',lineColor{j}, 'LineStyle', linestyle{j}};
plot(d(:,j), tau_g(:,j), options{:})
end
xlabel('distance d b/w mic pairs[cm]');
ylabel('\tau_g_r_o_u_n_d');
title('Relationship between \tau ground and distance between Mic Pairs for Array 3');
end
  댓글 수: 3

댓글을 달려면 로그인하십시오.


madhan ravi
madhan ravi 2018년 10월 8일
편집: madhan ravi 2018년 10월 8일
[~,sheets] = xlsfinfo('C:\Users\Bilal Ahmad\Desktop\Complete Simulations\Microphone Array 3_AllSources\AllSrc_MicArray3.xlsx');
lineColor = {'k', 'r', 'b', 'm','c','g','k','y','r','g','m','c','y','b','k','g'};
linestyle = {'-'; '--'; ':'; '-.';'-x';':';'-^';'->';'-v';'-s';'-p';'--';'-x';'-s';'-p';'--x'};
Legend = cell(16,1);
for i = 1:length(sheets)
data{i} = xlsread('C:\Users\Bilal Ahmad\Desktop\Complete Simulations\Microphone Array 3_AllSources\AllSrc_MicArray3.xlsx',sheets{i},'A4:T8');
d = data{i}(:,7);
tau_g = data{i}(:,9);
hold all
grid on
Legend{iter} = strcat('source', num2str(iter));
options = {'color',lineColor{j}, 'LineStyle', linestyle{j}};
plot(d, tau_g, options{:})
xlabel('distance d b/w mic pairs[cm]');
ylabel('\tau_g_r_o_u_n_d');
title('Relationship between \tau ground and distance between Mic Pairs for Array 3');
end
legend(Legend)
  댓글 수: 11
madhan ravi
madhan ravi 2018년 10월 9일
편집: madhan ravi 2018년 10월 11일
Then accept this answer to indicate the proper one

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by