why my plots are getting replaced after every simulation?

1 visualización (últimos 30 días)
Rakesh Roshan
Rakesh Roshan el 14 de Jun. de 2022
Comentada: Rakesh Roshan el 15 de Jun. de 2022
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
name = 1×1 cell array
{'Ram'}
s3 = 1×5
1.1200 1.7400 1.7000 2.5600 3.4500
s3 = 1×5
1.1200 1.7400 1.7000 2.5600 3.4500
s3 = 1×5
1.1200 1.7400 1.7000 2.5600 3.4500
s3 = 1×5
1.1200 1.7400 1.7000 2.5600 3.4500
Error using count
Not enough input arguments.
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 comentarios
Torsten
Torsten el 14 de Jun. de 2022
Maybe you forgot the "hold on" after the first plot command ?
Rakesh Roshan
Rakesh Roshan el 14 de Jun. de 2022
thank u sir i got all 24 plots sir but i am facing diffculty in giving its name it should be named as FIgure1_s1,Figure2_s2,Figure3_S3.....................................Figure24_s3. i am not getting it

Iniciar sesión para comentar.

Respuestas (2)

David Hill
David Hill el 14 de Jun. de 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 comentarios
Rakesh Roshan
Rakesh Roshan el 15 de Jun. de 2022
i am sorry sir but it didn't work for me.. i am getting only db plots and not magnitude
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');
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');
For 1st count properly all plots are coming but only dB not magnitude .i need to plot db and magnitude separately in two figure windows respectively numbered as 1,2,3,4,5
Rakesh Roshan
Rakesh Roshan el 15 de Jun. de 2022
hello sir plz respond

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 15 de Jun. de 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
  1 comentario
Rakesh Roshan
Rakesh Roshan el 15 de Jun. de 2022
sir i am using 2018a version export graphics command is not available

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by