필터 지우기
필터 지우기

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

조회 수: 99 (최근 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
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 CenterFile Exchange에서 Tables에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by