how to store a matlab code results in excel file (for multiple iterations)"
47 ビュー (過去 30 日間)
古いコメントを表示
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.
採用された回答
Jaswanth
2023 年 10 月 27 日
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!