why my plots are getting replaced after every simulation?
1 view (last 30 days)
Show older comments
T=readtable('88.xlsx');
T1=table2cell(T);
begin=csvread('count1.csv');%count for different no of person
for i=1:size(T,1)
name=[T{i,1}]
age=T1{i,2};
BP=T1{i,3};
res1=0;
for res=[0 1]
Tobegin(res,name,age,BP,res1)
end
res1=1;
for res=[0 1]
Tobegin(res,name,age,BP,res1)
end
if begin<size(T,1)% check whether all names are selected
begin=begin+1;%increment counter
dlmwrite('count1.csv',count) %write name of person number to csv file so that the program starts can run from person it stopped
else count=1;
dlmwrite('count1.csv',count)%initialise counter again
end
end
function Tobegin(res,name,age,BP,res1)
f=[8 9 10 11 12];
s1=[1 2 5 2 3];
figureplots1(f,s1)
s2=[2 4 8 9 10];
figureplots2(f,s2)
s3=[s1+s2];
figureplots3(f,s3)
rowsofdata1=[age BP res res1];
rowsofdata2=[age BP res res1];
dlmwrite('input1.csv',rowsofdata1,'-append','delimiter',',');
dlmwrite('input2.csv',rowsofdata2,'-append','delimiter',',');
end
function figureplots1 (f,s1)
a=figure;
plot(f,s1)
saveas(a,'Figure1_plot');
hold on
a1=figure;
plot(f,10*log(s1))
saveas(a,'Figure2_plot');
end
function figureplots2 (f,s2)
b=figure;
plot(f,s2)
saveas(b,'Figure1_plot');
hold on
b1=figure;
plot(f,10*log(s2))
saveas(b1,'Figure2_plot');
end
function figureplots3 (f,s3)
c=figure;
plot(f,s3)
saveas(c,'Figure3_plot');
hold on
c1=figure;
plot(f,10*log(s3))
saveas(c1,'Figure4_plot');
end
for each person 4 simulation is there here i have i written f ,s1,s2 values but every time it willl get varied..
my plots are getting replaced ..i.e after each simulation i am getting that particular result graph but as soon as it goes to next simulation plots gets replaced..with new simmulation s1 and s2 result
i should get as Figure1_plot
Figure2_plot
Figure3_plot
Figure4_plot.............total 16 plots i should get but i am getting 4 plots only
2018a version
4 Comments
Answers (2)
David Hill
on 14 Jun 2022
Question is confusing on figure numbering. Below saves 48 figures (16 each of s1, s2, and s3). Since you are saving the figures, no reason to plot all of them in window (yoiu can always pull up the saved figures).
T=readtable('88.xlsx');
T1=table2cell(T);
begin=readmatrix('count1.csv');
n=1;
for i=1:size(T,1)
name=[T{i,1}];
age=T1{i,2};
BP=T1{i,3};
res1=0;
for res=[0 1]
Tobegin(res,name,age,BP,res1,n);
n=n+1;
end
res1=1;
for res=[0 1]
Tobegin(res,name,age,BP,res1,n);
n=n+1;
end
if begin<size(T,1)
begin=begin+1;
writematrix(begin,'count1.csv')
else
writematrix(1,'count1.csv')
end
end
function Tobegin(res,name,age,BP,res1,n)
f=[8 9 10 11 12];
s1=[1 2 5 2 3];
figureplot(f,s1,n,'1')
s2=[2 4 8 9 10];
figureplot(f,s2,n,'2')
s3=s1+s2;
figureplot(f,s3,n,'3')
rowsofdata1=[name age BP f s1 res res1];
rowsofdata2=[name age BP f s2 res res1];
writecell(rowsofdata1,'input1.csv','WriteMode','append');
writecell(rowsofdata2,'input2.csv','WriteMode','append');
end
function figureplot(f,s1,n,n2)
plot(f,s1,f,10*log(s1));
saveas(gca,['Figure',num2str(n),'_plot_s',n2]);
end
2 Comments
Image Analyst
on 15 Jun 2022
Create a filename with sprintf, like
outputFolder = 'c:\wherever';
if ~isfolder(outputFolder)
mkdir(outputFolder)
end
for i=1:size(T,1)
% code to generate plots
% Now save the latest figure.
baseFileName = sprintf('Plot %2.2d.png', i);
fullFileName = fullfile(outputFolder, baseFileName);
exportgraphics(gca, fullFileName);
end
See Also
Categories
Find more on Printing and Saving in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!