how to store a matlab code results in excel file (for multiple iterations)"
47 views (last 30 days)
Show older comments
if i am running a matlab code for 10 iterations, that means the same code runs ten times. And every time it is generating an output result at command window. i just want to export the output result generated at command window to an excel file. the result should be store in 10 seperate coloumn since the number of iterations are 10. how should i do it.
Accepted Answer
Jaswanth
on 27 Oct 2023
Hi Ashish Das,
I understand that you would like to export the output results generated in the command window to an Excel file. To accomplish this, you can follow these steps:
- In your iteration code, store the output results in a matrix using indexing.
- Create a table of all the results using the "array2table" function.
- Finally, use the "writetable" function to export the table to an Excel file.
Please refer to following example for better understanding:
% Initialize variables
numIterations = 10;
outputResults = zeros(10, numIterations);
% Perform iterations
for iteration = 1:numIterations
% Generate random results for each iteration
result = rand(10, 1);
% Store results in outputResults matrix
outputResults(:, iteration) = result;
end
% Create a table from the outputResults matrix
resultsTable = array2table(outputResults);
% Export to Excel
writetable(resultsTable,'resultsTable.xls')
For more information on the functions used above, please refer to the following resources:
- array2table: Convert homogeneous array to table - https://in.mathworks.com/help/matlab/ref/array2table.html?s_tid=doc_ta
- writetable: Write table to file - https://in.mathworks.com/help/matlab/ref/writetable.html?s_tid=doc_ta
Hope this Helps.
Regards,
Jaswanth
More Answers (0)
See Also
Categories
Find more on Spreadsheets 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!