load and plot many .mat files in a loop

조회 수: 5 (최근 30일)
Siriki Kone
Siriki Kone 2022년 6월 24일
댓글: Voss 2022년 6월 25일
Hi, i have many .mat files which i would like to plot in the same figure. The problem is my data are not loading in my for loop:
close all
clear all
clc
load('C:\ordner1\ordner2\tc.mat');
Path='C:\ordner1\ordner2\Station_01\hhz';
P=strcat(Path,'\PSDPDFs\1120\') %P=strcat(Path,'\hhe\06\');
S=(fullfile(P,'*.mat'));
AllFiles=dir(S);
for kk=1:5 %numel(AllFiles)
File3=AllFiles(kk).name;
Data = load(File3); %load(strcat(P,File3));
semilogx(tc,Data.Z3)
hold on
end
xlabel('Period (s)')
ylabel('Power 10*log10 (m/s^2)/Hz or dB')
title('PSDPDF diagram containing 1 month of Data composed of 1 Hour segments')
axis tight
hold off
as i said i become an error with the load function:
Error using load
Unable to read file 'PSDPDF1.mat'. No such file or directory.
Error in plot_PSDPDF (line 13)
Data = load(File3); %load(strcat(P,File3));
i try another code by changing load(File3) with load(strcat(P,File3)):
close all
clear all
clc
load('C:\ordner1\ordner2\tc.mat');
Path='C:\ordner1\ordner2\Station_01\hhz';
P=strcat(Path,'\PSDPDFs\1120\') %P=strcat(Path,'\hhe\06\');
S=(fullfile(P,'*.mat'));
AllFiles=dir(S);
for kk=1:5 %numel(AllFiles)
File3=AllFiles(kk).name;
Data=load(strcat(P,File3));
semilogx(tc,Data)
hold on
end
xlabel('Period (s)')
ylabel('Power 10*log10 (m/s^2)/Hz or dB')
title('PSD diagram containing 1 month of Data composed of 1 Hour segments')
axis tight
hold off
i got another error message:
Error using semilogx
Unrecognized property PSDPDF for class Line.
Error in plot_PSDPDF_220624 (line 14)
semilogx(tc,Data)
can someone help me with that

답변 (1개)

Voss
Voss 2022년 6월 24일
편집: Voss 2022년 6월 24일
Try it like this
Data=load(strcat(P,File3));
semilogx(tc,Data.Z3)
Somehow you dropped off the .Z3 when you tried this
Data=load(strcat(P,File3));
semilogx(tc,Data)
  댓글 수: 2
Siriki Kone
Siriki Kone 2022년 6월 25일
ooh I forgot to say, i did try it too, i got the following msg:
Unrecognized field name "Z3".
Error in plot_PSDPDF_220624 (line 14)
semilogx(tc,Data.Z3)
Data should actually be my psdpdf (97,1) mat file but instead of that i get this:
Data =
struct with fields:
PSDPDF: [97×1 double]
Voss
Voss 2022년 6월 25일
Data=load(strcat(P,File3));
semilogx(tc,Data.PSDPDF)

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

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by