how can i store the result which i am obtaining on command window and store it on in excel file, i have tried but still not able to solve it out.

3 次查看(过去 30 天)
% Initialize variables
numIterations = 10;
outputResults = zeros(10, numIterations);
% Perform iterations
for iteration = 1:numIterations
% Generate random results for each iteration
result = rand(10, 1);
run('start.m'); % my main program to be run for 10 iterations%
% 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')
  4 个评论
Dyuman Joshi
Dyuman Joshi 2023-11-27
Why not define the code as a function and provide the data you want to save in terms of output variable(s)?
This way you can call the function in each iteration and store the data accordingly.
What is it, that is displayed on the command window which you want to capture?

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2023-11-26
If you cannot modify the script for some reason, then change
run('start.m'); % my main program to be run for 10 iterations%
to
start_results = evalc('start');
and then use tools such as regexp() to extract the parts you want out of the output.
But if you can modify the script to return a value, that would almost always be better.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import from MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by