Info

この質問は閉じられています。 編集または回答するには再度開いてください。

how to store multpile files which has been loaded first in the same script ,in the new variable , through loop

1 回表示 (過去 30 日間)
Daniyal Arif
Daniyal Arif 2019 年 8 月 6 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
i want to write second part through loop
please guide about it
my matlab is release is 2016a

回答 (1 件)

David K.
David K. 2019 年 8 月 6 日
So, I believe this answer could be done using the eval function but since that function is highly discouraged here is my attempt at doing this without using it.
First, make sure all of your .mat files are in the folder you are using alone
Files = dir('*.mat'); % dir('SH*.mat') may work as well if you dont want to change folders
jan = zeros();
feb = zeros(); % Preallocate to whatever size you need
for n = 1:length(Files)
data = load(Files(n).name); % Load in a new set of data
dataCell = struct2cell(data); % Switch to cell so we can get the data without knowing the data
jan(:,n) = dataCell{1};
feb(:,n) = dataCell{2};
% Instead of assigning each month we could do this instead:
for month = 1:12 % Assuming you have all months
totalData(:,n,month) = dataCell{month}; % Should preallocate this as well if you choose to do it
end
end
Hope this works for you, I dont have the data so hard to test to be sure.
And if any more experienced people see this I would be interested to know how proper this method would be considered.

Community Treasure Hunt

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

Start Hunting!

Translated by