save each array of a cell as sequence xls files

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Data Import and Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by