How to plot and export two figures by using a "for" loop?
Mostrar comentarios más antiguos
Hello everyone! In my script I have many duplicated section used to plot couple of figures whose codes are parametrized for couples of numbers, i.e. I have a database for two different cases and I have to produce and then export as .pdf images couples of images that differes from each other (inside the couple only for one parameter).
Here there is an example code to let you understand my previous lines:
clear all; close all; clc;
x1 = linspace(1,100,100);
x2 = linspace(2,200,100);
X = [x1;x2];
% for i = 1:2
% First plot
fig=figure;
plot(X(1,:),cos(X(1,:)),'Color',[0 0.44 0.36]);
legend('function 1');
xlabel('x_1');
ylabel('y_1');
dim = [.168 .85 .275 .06];
str = ['annotation box no.',num2str(numel(x1(2))),];
annotation('textbox',dim,'String',str,'Interpreter',"latex",'FitBoxToText','off',...
'BackgroundColor',[1 1 1],'FontSize',9);
grid on;
set(gcf,'position',[278.6, 0.2, 600, 400]); %aspect ratio 3/2
%exportgraphics(fig,'fig_test1.pdf','ContentType','vector'); %salva
% Second plot
fig=figure;
plot(X(2,:),cos(X(2,:)),'Color',[0.2 0.24 0.46]);
legend('function 2')
xlabel('x_2');
ylabel('y_2');
str = ['annotation box no.',num2str(numel(x2(1))),];
annotation('textbox',dim,'String',str,'Interpreter',"latex",'FitBoxToText','off',...
'BackgroundColor',[1 1 1],'FontSize',9);
grid on;
set(gcf,'position',[278.6, 0.2, 600, 400]); %aspect ratio 3/2
%exportgraphics(fig,'fig_test2.pdf','ContentType','vector'); %salva
% end
As you can see, the differences are about the indices 1 and 2 related to the variables to plot.
I would to get the same results you can see in my example code, i.e. two separated figures in .mlx Matlab file and then two separated .pdf images, but using a "for" loop so as to reduce lines of code and lighten Matlab runs. Can you help me to code using "for"loop to get my goals?
Thanks in advance.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Image Arithmetic en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


