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 CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by