Building the legend according to user input.

2 views (last 30 days)
Hey all,
Hope everyone doing good.
I have a small question here.
I need to get the legend according to input.
Below is my code;
n = 50;
[f,T1, X] = Samplemodel_Instat('Measuring_Data.mat');
%X = {[ 2 4 6] ['Node2' 'Node4' 'Node6']};
for plotnumber = 1:n
c = find(X{1,1} == plotnumber,1);
if ~isempty(c)
c = plotnumber;
if n <= 3
plot(f(1:150:end)/3600,T1(c,1:150:end),'Color',[0.831372559070587 0.815686285495758 0.7843137383461]);
% legend(X{1+1}(col,row));
%plot(f(1:200:end)/3600,T1(c,1:200:end),'DisplayName',X{1+1}(col,row));
elseif n > 3
if c >= 1 && c <= ceil(n./4)
plot(f(1:200:end)/3600,T1(c,1:200:end),'Color',[0.25 0.25 0.25],'LineWidth',4,'LineStyle','-.','MarkerFaceColor',[1 1 1],'Marker','none');
% legend(X{1+1}(col,row));
%plot(f(1:200:end)/3600,T1(c,1:200:end),'DisplayName',X{1+1}(col,row));
elseif c > (ceil(n./4)) && c <= ceil(n./2)
plot(f(1:200:end)/3600,T1(c,1:200:end),'Color',[0.952941179275513 0.87058824300766 0.733333349227905],'LineWidth',2,'MarkerFaceColor',[1 1 1],'Marker','s');
% legend(X{1+1}(col,row));
%plot(f(1:200:end)/3600,T1(c,1:200:end),'DisplayName',X{1+1}(col,row));
elseif c > (ceil(n./2)) && c <= ceil(3*n./4)
plot(f(1:200:end)/3600,T1(c,1:200:end),'Color',[0.31 0.31 0.31],'LineWidth',2,'LineStyle','-','Marker','d','MarkerFaceColor',[1 1 1]);
% legend(X{1+1}(col,row));
%plot(f(1:200:end)/3600,T1(c,1:200:end),'DisplayName',X{1+1}(col,row));
elseif c > (ceil(3*n./4)) && c <= n
plot(f(1:150:end)/3600,T1(c,1:150:end),'Color',[0.831372559070587 0.815686285495758 0.7843137383461]);
% legend(X{1+1}(col,row));
%plot(f(1:200:end)/3600,T1(c,1:200:end),'DisplayName',X{1+1}(col,row));
end
end
end
end
Here I need to get the legend everytime for the respective c.
For an example if c = 2, legend should be Oil. You can see how c become 2 in X above.
I hope that it is eary to understand.
Any suggestions and answered are most welcomed.
Thanks in advance

Accepted Answer

Jon
Jon on 1 Jul 2019
It is a little hard to understand all of the details of what you are doing in your code, and what exactly you want to produce for plots. If I am understanding correctly, I think you should be able to do what you want by setting the DisplayName property when you plot the line.So put your possible legend names in a cell array e.g. names = {'Oil','Air','Material'}, and then index appropriately when you plot the line, to set the DisplayNamso something like,
plot(f(1:200:end)/3600,T1(c,1:200:end),'DisplayName',names{k})
, where k is the appropriate index.
  3 Comments
surendra kumar Aralapura mariyappa
@Jan
Thank you for your kindness. Actually I was bit confused. Because, I was stressed out myself while doing this. Then I got to know my mistakes. Now It is working properly. All your collegaues helped me out a lot.
Anyways thank you once again.

Sign in to comment.

More Answers (0)

Products


Release

R2014a

Community Treasure Hunt

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

Start Hunting!