Unsing string for indexing though structures

2 ビュー (過去 30 日間)
Jan-Philipp Göbel
Jan-Philipp Göbel 2022 年 9 月 28 日
コメント済み: Jan-Philipp Göbel 2022 年 9 月 28 日
Hey, I would like to create a while loop with which I can read mat files one after the other and evaluate them automatically without writing a separate program for each mat file. Loading the mat files works using the loop, but unfortunately I can't access the structures with a variable s2.
Does someone have a solution for it?
i = 108;
% A = ((0.1255)/2)^2*pi;
% ml_in_m3 = 1e-6;
while i <= 108
pfad = '...';
s = strcat(pfad,'Test3_',string(i),'.mat');
s2 = strcat('Test3_',string(i));
load(s);
figure(2)
plot(s2.X.Data,s2.Y(8).Data)
t = s2.X.Data;
y = s2.Y(8).Data;
x = 0:0.001:s2.X.Data(end);
y=interp1(t,y,x,'spline');
i = i+1;
end
%the error that occur is: Unrecognized method, property, or field 'X' for class 'string'.

回答 (1 件)

KSSV
KSSV 2022 年 9 月 28 日
編集済み: KSSV 2022 年 9 月 28 日
i = 108;
% A = ((0.1255)/2)^2*pi;
% ml_in_m3 = 1e-6;
while i <= 108
pfad = '...';
s = strcat(pfad,'Test3_',string(i),'.mat');
% s2 = strcat('Test3_',string(i));
s2 = load(s); % <--changed here
figure(2)
plot(s2.X.Data,s2.Y(8).Data)
t = s2.X.Data;
y = s2.Y(8).Data;
x = 0:0.001:s2.X.Data(end);
y=interp1(t,y,x,'spline');
i = i+1;
end
  3 件のコメント
KSSV
KSSV 2022 年 9 月 28 日
Do all mat files have same variable names?
Jan-Philipp Göbel
Jan-Philipp Göbel 2022 年 9 月 28 日
yeah, only the name of the file and the values of the variables are changing

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by