Saving each data from for loop

6 ビュー (過去 30 日間)
helia mb
helia mb 2019 年 11 月 25 日
編集済み: helia mb 2019 年 11 月 29 日
Hello, I have a for loop that count from 1 to 200 . And these 200 are number of my file that gonna read in matlab. I want to read each file and save it.but lenght of my files aren't same as each other.how can I save each of them?! Wgen I running my for loop it just save the last data.
if true
For i =1:200
Clc
Close all
Ss2 %my matrix are in there
Wanna save each of them
End
end
  2 件のコメント
Michal
Michal 2019 年 11 月 25 日
Hi, by 'how can I save each of them?!' do you mean saving the contents of the files in one variable? What are the contents of the files?
helia mb
helia mb 2019 年 11 月 25 日
Yes,they are series of numbers about 38×360000, but the column in each file are varied. When i load my for loop , it reads each of them but at the end i can see just the last matrix, that means other doesn't save in workspaces

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

回答 (1 件)

Philippe Lebel
Philippe Lebel 2019 年 11 月 25 日
編集済み: Philippe Lebel 2019 年 11 月 25 日
If you want to store elements (like strings) that are not the same size you can use cells.
A = {'abc', 'defg', 'hijklmnop', 123, [4,5,6,7,8], false}
A =
'abc' 'defg' 'hijklmnop' [123] [1x5 double] [0]
So if you want to go through a bunch of files and put their content in a cell you can do it this way (pseudo code)
my_list_of_files= {'file1','file2', 'file3'}
my_array = {};
for i=1:length(my_list_of_files)
my_array{i} = read(my_list_of_files{i});
end
  12 件のコメント
Stephen23
Stephen23 2019 年 11 月 29 日
"I don't know how to insert them in a cell array..."
N = number of files
C = cell(1,N);
for k = 1:N
... import your data
YourData = ... whatever
C{k} = YourData; % store your data in a cell array
end
"...plus my column data size aren't same as each other.during reading each file"
Is irrelevant if you are using a cell array.
helia mb
helia mb 2019 年 11 月 29 日
Yes exactly that's what I mean...oh my god Thank you so much~~ you are amazing

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

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by