Export variables of for loop into an excel sheet
Show older comments
for i = 0.01:0.01:0.04
A = i*5;
fprintf('%02d \n',A)
end
xlswrite('xlx.xlx',A);
How can I export the values into an excel sheet? Is this the correct formula?
Answers (1)
KL
on 10 Nov 2017
You probably want to store your loop iterations in an array.
A = zeros(1,10); %pre-allocate
for k=1:size(A,2) %use A's size
A(1,k) = k*10; %populate (do your computations)
end
xlswrite('filename.xls',A)
2 Comments
JG
on 10 Nov 2017
There's a reason why I used k as the iterator in the for loop. i and j are the default imaginary units and unlike other programming languages, it's better practice to avoid using them as iterators in matlab.
Categories
Find more on Data Import from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!