Create loop to load .mat file and store values to a matrix.
3 ビュー (過去 30 日間)
古いコメントを表示
I have multiple .mat files with values for x and y. The variables in each file has the same name (x,y) , but different values.
I need to create a loop or a function that loads each file and will open them one at a time and save x and y (maybe in a matrix) in order to be able to plot them. Any thoughts?
0 件のコメント
採用された回答
Stephen23
2021 年 12 月 7 日
編集済み: Stephen23
2021 年 12 月 7 日
This should get you started. In the absence of any data desription I assumed that withinin each file x and y are scalar. You will need to adapt to suit your filenames, data sizes, etc.:
P = 'absolute or relative file path to where the files are saved';
S = dir(fullfile(P,'*.mat'));
S = natsortfiles(S); % optional, if required download from FEX 47434.
for k = 1:numel(S)
F = fullfile(P,S(k).name);
S(k).data = load(F);
end
D = [S.data];
X = vertcat(D.x);
Y = vertcat(D.y);
plot(X,Y)
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!