Hold legend in matlab

146 views Asked by At

i have a code which is used to analyse some raw data data and compare the results of many(unknown number) of tests. for this my code first starts like this

prompt='how many files do you wish to analyse? ';
prompt1='what is the name of the test?  ';
prompt2='what is the name of the file? ';

n=input(prompt);

for i=1:n
    name(i,:)=input(prompt1,'s');
    filename(i,:)=input(prompt2);
end
for i=1:n
    a(:,:,i)=ftp_75_2(filename(i,:));
    for j=1:18
        figure(j)
        legend(name(i,:));
    end
end

the trouble is every time a new legend gets added the old one gets removed. can someone help me. I have seen some solutions online but they all require the person who runs the code to create a specific label command or to know the number of files which will be in the legend rather than take an input from the user.

I am creating this code to give prompts since the people who are to use this will have little to no matlab knowledge

1

There are 1 answers

0
zeeMonkeez On

You can assign a DisplayName during creation in your function that performs the plots, like so:

plot(3:-1:1,1:3, 'DisplayName', 'My title')

You can do this for your various tests, and then, at the end, you can call

legend(findobj(j, '-property', 'DisplayName'))

(where j is your figure handle) to display the legend.