how to store a matlab code results in excel file (for multiple iterations)"

47 ビュー (過去 30 日間)
Ashish Das
Ashish Das 2023 年 10 月 26 日
コメント済み: Ashish Das 2023 年 11 月 3 日
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
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:
  1. In your iteration code, store the output results in a matrix using indexing.
  2. Create a table of all the results using the "array2table" function.
  3. 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:
  1. array2table: Convert homogeneous array to table - https://in.mathworks.com/help/matlab/ref/array2table.html?s_tid=doc_ta
  2. writetable: Write table to file - https://in.mathworks.com/help/matlab/ref/writetable.html?s_tid=doc_ta
Hope this Helps.
Regards,
Jaswanth
  1 件のコメント
Ashish Das
Ashish Das 2023 年 11 月 3 日
Hi jaswanth Thanks for you Answer:
well i am still not been able to get it done.
below is my code which i am writing to run a code for 10 times and want to store my results.
I am able to run the program for 0 time, but to store the results, is where i am still having problem.
clc;clear;
Iteration=5;
ouput_Results=zeros(10,Iterations);
%%%%%%%%%%%%%%% For Fixing SEED %%%%%%%%%%%%%%%%%%%%%
for i=1:Iteration
disp('i=');
disp (i);
%rand('seed', i); %%% fixing seed
rng(i,"twister");
x=rand();
%disp(rng.seed);
run('start.m'); %%%%% start.m is the main matlab code which i want to run for 10 time. %%%%%%
% Store results in outputResults matrix
output_Results(:, iteration) = result;
%for j=1:ouput_data
% disp('j=');
% disp (j);
%diary i.txt
% Create a table from the outputResults matrix
resultsTable = array2table(output_Results);
% Export to Excel
writetable(resultsTable,'resultsTable.xls')
end
can you help me to sought out this problem

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by