generating files using loop or other functions

2 views (last 30 days)
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.

Sign in to comment.

Accepted Answer

Sudhakar Shinde
Sudhakar Shinde on 27 Oct 2020
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

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!