필터 지우기
필터 지우기

how to save plots in a folder. named as figure1,Fi​gure2,Figu​re3,Figure​4?

조회 수: 2 (최근 30일)
Rakesh Roshan
Rakesh Roshan 2022년 5월 18일
댓글: Voss 2022년 5월 19일
i have 40 list of people data
each data is having 2 data of age
i have used image below to explain it clearly
so from age data a1 4 graphs and a2 4 graphs
from 1 data i am getting 8 graphs..
i am facing difficulty to save graphs numbered as figure1,figure2 in a folder
a=dlmread('S11.txt')
freq=a(:,1)
Spam=a(:,2)
Spam=reshape(Spam,[1,21])
x = freq;
y = spam;
plot(x,y);
grid on
title('plot');
xlabel('freq');
ylabel('sparm');
is there any command which will find out no of figures already generated and then based on that save the figures
like this i have to plot for multiple sparameters ..how to save it as figure1 figure2 .figure 3 in jpg format in folder
2018a version

채택된 답변

Voss
Voss 2022년 5월 18일
편집: Voss 2022년 5월 18일
files = dir('*.txt');
files = fullfile({files.folder},{files.name});
for ii = 1:numel(files)
a=readmatrix(files{ii});
f = figure();
plot(a(:,1),a(:,2));
grid on
title('plot');
xlabel('freq');
ylabel('sparameter');
saveas(f,sprintf('figure%d.jpg',ii));
delete(f);
end
dir('*.jpg')
figure1.jpg figure2.jpg
  댓글 수: 4
Rakesh Roshan
Rakesh Roshan 2022년 5월 19일
Thank you sir, this worked well...in my code ...and i got the way to read from ascii file from documentation
now sir i am facing problem in storing these values in text files in .csv format
sir in some files i am getting no of samples in text files around 500 or 1001 or 1107,2001 i am using this commands
a=reshape(a(:,2),[1,500])
dlmwrite('output.csv',a.'-append')
but no luck as i am getting and error
is there any way where i can control reshaping i.e how much ever elements are there i have to fix it to 1 row and 500 columns only.
Voss
Voss 2022년 5월 19일
To take the first 500 elements of column 2 of a, convert it to a row vector, and store it as a:
a = a(1:500,2).';
If there are fewer than 500 elements, you'd have to augment to 500, if you always need it to be 500.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by