how to plot separately ..plots getting replaced?

1 view (last 30 days)
for each no of person i should 6 plots properly numbered but i am not getting ..plz correct the error
T=readtable('88.xlsx');
T1=table2cell(T);
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]
for j=[25]
Tobegin(res,name,age,BP,res1,n)
end
n=n+1;
end
end
function Tobegin(res,name,age,BP,res1,n)
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,n)
plot(f,s1,'-r','LineWidth',3)
ax=gca;ax.YAxis.Exponent=0;grid on
ylabel('S1')
xlabel('freq')
title('dB')
saveas(gca,['Figure',num2str(n),_S1_dB,'.jpg');
plot(f,10*log(s1),'-r','LineWidth',3)
ax=gca;ax.YAxis.Exponent=0;grid on
ylabel('S1')
xlabel('freq')
title('Magnitude')
saveas(gca,['Figure',num2str(n),_S1_abs,'.jpg');
end
function figureplots2 (f,s2,n)
plot(f,s2,'-r','LineWidth',3)
ax=gca;ax.YAxis.Exponent=0;grid on
ylabel('S2')
xlabel('freq')
title('dB')
saveas(gca,['Figure',num2str(n),_S2_dB,'.jpg');
plot(f,10*log(s2),'-r','LineWidth',3)
ax=gca;ax.YAxis.Exponent=0;grid on
ylabel('S2')
xlabel('freq')
title('Magnitude')
saveas(gca,['Figure',num2str(n),_S2_abs,'.jpg');
end
function figureplots3 (f,s3,n)
plot(f,s3,'-r','LineWidth',3)
ax=gca;ax.YAxis.Exponent=0;grid on
ylabel('S3')
xlabel('freq')
title('dB')
saveas(gca,['Figure',num2str(n),_S3_dB,'.jpg');
plot(f,10*log(s3),'-r','LineWidth',3)
ax=gca;ax.YAxis.Exponent=0;grid on
ylabel('S3')
xlabel('freq')
title('Magnitude')
saveas(gca,['Figure',num2str(n),_S3_abs,'.jpg');
end
2018 a version
  1 Comment
Walter Roberson
Walter Roberson on 16 Jun 2022
What is the purpose of the for j loop? You do not use j in your code.

Sign in to comment.

Answers (1)

Voss
Voss on 15 Jun 2022
Edited: Voss on 15 Jun 2022
You had some syntax errors in constructing your file names, and a missing argument in your calls to figureplots*.
Check the code below.
T=readtable('88.xlsx');
T1=table2cell(T);
for i=1:size(T,1)
name=[T{i,1}];
age=T1{i,2};
BP=T1{i,3};
f=[8 9 10 11 12];
s1=[1 2 5 2 3];
figureplots1(f,s1,i)
s2=[2 4 8 9 10];
figureplots2(f,s2,i)
s3=[s1+s2];
figureplots3(f,s3,i)
res1=0;
for res=[0 1]
Tobegin(res,age,BP,res1)
end
res1=1;
for res=[0 1]
for j=[25]
Tobegin(res,age,BP,res1)
end
end
end
delete(gcf());
ls *.jpg % Here is a list of your images. Is it as expected now???
Figure1_S1_abs.jpg Figure1_S2_dB.jpg Figure2_S1_abs.jpg Figure2_S2_dB.jpg Figure3_S1_abs.jpg Figure3_S2_dB.jpg Figure4_S1_abs.jpg Figure4_S2_dB.jpg Figure1_S1_dB.jpg Figure1_S3_abs.jpg Figure2_S1_dB.jpg Figure2_S3_abs.jpg Figure3_S1_dB.jpg Figure3_S3_abs.jpg Figure4_S1_dB.jpg Figure4_S3_abs.jpg Figure1_S2_abs.jpg Figure1_S3_dB.jpg Figure2_S2_abs.jpg Figure2_S3_dB.jpg Figure3_S2_abs.jpg Figure3_S3_dB.jpg Figure4_S2_abs.jpg Figure4_S3_dB.jpg
function Tobegin(res,age,BP,res1)
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,n)
plot(f,s1,'-r','LineWidth',3)
ax=gca;ax.YAxis.Exponent=0;grid on
ylabel('S1')
xlabel('freq')
title('dB')
saveas(gca,['Figure',num2str(n),'_S1_dB','.jpg']);
plot(f,10*log(s1),'-r','LineWidth',3)
ax=gca;ax.YAxis.Exponent=0;grid on
ylabel('S1')
xlabel('freq')
title('Magnitude')
saveas(gca,['Figure',num2str(n),'_S1_abs','.jpg']);
end
function figureplots2 (f,s2,n)
plot(f,s2,'-r','LineWidth',3)
ax=gca;ax.YAxis.Exponent=0;grid on
ylabel('S2')
xlabel('freq')
title('dB')
saveas(gca,['Figure',num2str(n),'_S2_dB','.jpg']);
plot(f,10*log(s2),'-r','LineWidth',3)
ax=gca;ax.YAxis.Exponent=0;grid on
ylabel('S2')
xlabel('freq')
title('Magnitude')
saveas(gca,['Figure',num2str(n),'_S2_abs','.jpg']);
end
function figureplots3 (f,s3,n)
plot(f,s3,'-r','LineWidth',3)
ax=gca;ax.YAxis.Exponent=0;grid on
ylabel('S3')
xlabel('freq')
title('dB')
saveas(gca,['Figure',num2str(n),'_S3_dB','.jpg']);
plot(f,10*log(s3),'-r','LineWidth',3)
ax=gca;ax.YAxis.Exponent=0;grid on
ylabel('S3')
xlabel('freq')
title('Magnitude')
saveas(gca,['Figure',num2str(n),'_S3_abs','.jpg']);
end
  5 Comments
riki singh
riki singh on 16 Jun 2022
Sir figure plots i have to include in to begin function ..because data in tobegin function is only generating f S1,S2 data... After each simulation figure nos has to get incremented

Sign in to comment.

Tags

Products

Community Treasure Hunt

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

Start Hunting!