필터 지우기
필터 지우기

How to save multiple polts with the source file name using loop?

조회 수: 1 (최근 30일)
Rajeev Kumar
Rajeev Kumar 2023년 2월 11일
댓글: Rik 2023년 2월 11일
How to save multiple polts with the source file name using loop?
Code
folder = "C:\Users\91743\OneDrive\Documents\MATLAB\MATLAB\Files"; % specify the path to the folder
%filepattern=fullfile(folder,'.csv');
files = dir(fullfile(folder, '*.mat')); % get a list of all .mat files in the folder
nFiles = numel(files); % number of files in the folder
for i = 1:nFiles
signal=fullfile(folder, files(i).name); % load the signal from the .mat file
%x = signal; % extract the signal from the .mat file
% signal1=signal(:,1);
D = load(signal); % ugh ugh ugh, that ugly prefix on those poor variable names!
D = cell2struct(struct2cell(D),regexprep(fieldnames(D),'^\w\d+_?',''),1); % much better.
files(i).data = D;
D=[files.data];
current_signal=D(i).DE_time;
%signal1=struct2array(signal);
%field_names=getfield(signal);
%current_signal=field_names{1};
%disp(current_signal);
%current_signal1=load(current_signal'.mat');
%current_signal1=
Fs=51200; %sampling frequency
T=1/Fs; %sampling period
L=length(current_signal); %Lenght of the signal
%t=((0:L-1)*T);
req=((0:L-1)*Fs/L);
xdft1 = fft(current_signal); %Compute FFT
xdft1 = 1/L*xdft1; %Normalize
xdft1(2:end-1) = 2*xdft1(2:end-1);
X_mag = abs(xdft1);
freq=((0:L-1)*Fs/L);
%X = fft(signal); % compute the FFT of the signal
%magX = abs(X); % magnitude of the FFT
%phaseX = angle(X); % phase of the FFT
figure;
plot(freq,X_mag,'LineWidth',1);
xlim([0 1000]);
xlabel('Frequency (Hz)');
ylabel('Acceleration (g)');
%savefig([field_names num2str(i) '.fig']);
end

답변 (1개)

Rik
Rik 2023년 2월 11일
You have all elements already in your code. Why not uncomment savefig and use files(i).name?
  댓글 수: 4
Rajeev Kumar
Rajeev Kumar 2023년 2월 11일
'savefig and use files(i).name' is not worked for save the all graph.
Rik
Rik 2023년 2월 11일
What code did you try and how did the result differ from what you want. I can't read your mind and I can't see your computer screen, so you will have to explain these things.

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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by