MATLAB Answers

Olivier

How to save a *.fig with the legend included?

Asked by Olivier
on 26 May 2013
Latest activity Answered by Adam Neufeldt
on 21 May 2015 at 20:14

Hi,

My question is quite simple :

I have the following code :

figure;
A = loglog(...)
hold on
B = loglog(...)
C = loglog(...)
      str = sprintf('3SRS - Run %d - Dir %d', run, dir);
      title(str);
      xlabel('Fréquences [Hz]');
      ylabel('Accel (G)');
      legend( [A B C], '...','...','...' );
      filename = str;
      saveas(figure(1),filename,'fig');
      close figure 1

And it appears that the figure is correctly saved in .fig but the legend isn't displayed when i open the saved *.fig

Thanks in advance. O.G.

  2 Comments

the code is not work. It's a example or the real code?

Olivier
on 26 May 2013

Hm yes sorry, it was just an example... The '...' are full filled with my data. I put some '...' because you coudn't acces to my data.

Products

No products are associated with this question.

3 Answers

Answer by Artur M. G. Lourenço on 26 May 2013

Try this,

 figure;
A = loglog(1:50)
hold on
B = loglog(1:50)
C = loglog(1:50)
      str = sprintf('3SRS - Run %d - Dir %d');
      title(str);
      xlabel('Fréquences [Hz]');
      ylabel('Accel (G)');
      legend( [A B C], 'Test A','Test B','Test C' );
      filename = str;
      saveas(figure(1),filename,'fig');
      close figure 1

  1 Comment

Olivier
on 26 May 2013

As I said above, the '...' are full filled with my data. It's a general scheme where I point out the problem that my legend isn't saved in the .fig figure.

Thanks if you can give me more explanations.


Answer by Image Analyst
on 26 May 2013

  2 Comments

Olivier
on 26 May 2013

I'm sorry but i don't think it answers my question... Thanks, however.

Image Analyst
on 26 May 2013

export_fig (the most downloaded file from the File Exchange, and recommended by the FAQ) will save the entire figure or axes. I'd be surprised if saved everything except the legend.


Answer by Adam Neufeldt
on 21 May 2015 at 20:14

I'm having the same problem, have you found the solution to fix this?

  0 Comments


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply today