save each array of a cell as sequence xls files

1 回表示 (過去 30 日間)
Shabnam M
Shabnam M 2020 年 4 月 14 日
コメント済み: Shabnam M 2020 年 4 月 14 日
Hello Every one,
In the code bellow, I have tried to read .csv files which were named as "Book1, Book2, Book3,..." (I have 5000 .csv as mentioned tempelate from experiments)
I just wanted to keep 4 columns and also rows which positive values.
after that I need to save each of them again as new files like "new1, new2, new3, ...."
I've got stucked on saving them cause I prepare cell to do that calculation and now I need to write each array of cell as a seperate file.
here is my code:
files = dir ('E:.......\Book*.csv')
N = length(files);
data = cell (1,N);
for i=1:N
data {i} = csvread(files(i).name);
modified {i} = data{i} (: , [1 2 4 5]);
new {i} = modified {i} (modified {i} (:,1)>0, :);
end
I will be so thankful if you can help me to now save the new{i} as seperated files with sequence.
Best Regards,

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 4 月 14 日
編集済み: Ameer Hamza 2020 年 4 月 14 日
There are several functions to save data in MATLAB
The variable new {i} is probably a numeric matrix, so you can write
writematrix(new{i}, ['new' num2str(i) '.csv'])
  7 件のコメント
Ameer Hamza
Ameer Hamza 2020 年 4 月 14 日
try something like this
new{i} = array2table(new{i}, 'VariableNames', {'column1', 'column2', 'column3', 'column4'}); % write name of the columns
writetable(t, ['new' num2str(i) '.csv'], 'WriteVariableNames', 1)
Shabnam M
Shabnam M 2020 年 4 月 14 日
I really appreciate your help, Thank you so much

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by