generating files using loop or other functions

조회 수: 1 (최근 30일)
Abdulkarim Almukdad
Abdulkarim Almukdad 2020년 10월 26일
댓글: Sudhakar Shinde 2020년 10월 27일
I have the attached data and I want to create an excel sheet with name Test1 that includes the 1st column with the 2nd column, then to create another files with name Test2 that includes the 1st column with the 3rd column and so on assuming I have many columns. Thanks in advance.
  댓글 수: 2
Stephen23
Stephen23 2020년 10월 27일
편집: Stephen23 2020년 10월 27일
To future readers: the accepted answer uses inefficient, complex code to access the table variables.
Do NOT follow this bad code example!
My comment below the answer shows the simpler, neater, less buggy, easier to debug, and much more efficient approach (i.e. the one given in the MATLAB documentation). Do NOT learn bad ways of writing MATLAB code.
Sudhakar Shinde
Sudhakar Shinde 2020년 10월 27일
@Stephen, Thanks for your comment.

댓글을 달려면 로그인하십시오.

채택된 답변

Sudhakar Shinde
Sudhakar Shinde 2020년 10월 27일
Use readtable and writetable functions.
Data=readtable('x1)Data.xlsx'); % Read excel data
[R,C]=size(Data); % get number of columns
VariableNames = Data.Properties.VariableNames; % Name of each column heading
for i=2:C
Out.Nu = eval(['Data.',VariableNames{1}]); % 1st column
Out.Var = eval(['Data.',VariableNames{i}]) ;
Table = table(Out.Nu,Out.Var);
writetable(Table,['Test' num2str(i-1),'.xlsx']); %%write into excel exmaple: Test1.xlsx
end
  댓글 수: 5
Abdulkarim Almukdad
Abdulkarim Almukdad 2020년 10월 27일
I have used it and gave me the same answer. Thanks all.
Sudhakar Shinde
Sudhakar Shinde 2020년 10월 27일
Welcome.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by