Need help to write general syntax for matlab program for combining results of all inputs
조회 수: 1 (최근 30일)
이전 댓글 표시
If i have a matlab program which requires input d. suppose i want to get results for d=8 and d=9. i can run program separately like- every time for d=8 and get result, then for 9 and get result.
for example for d=8, i get
A=
1 2
2 3
then again for d= 9, i get
A=
1 7
0 6
How can i modify my program to store result from previous input, so that it display result as for d= 8, d= 9 together as
*1 2
2 3*
1 7
0 6
댓글 수: 0
답변 (3개)
Guillaume
2014년 8월 21일
편집: Guillaume
2014년 8월 22일
You could use arrayfun to stash your outputs into a cell array and then cell2mat to transform that array into a matrix of of the right shape. e.g: assuming your program (function) is called myprogram:
proginputs = [8 9]; %whatever you want them to be
progoutputs = arrayfun(@myprogram, proginputs, 'UniformOutput', false);
outputmatrix = cell2mat(progoutputs'); transposed as you want the outputs concatenated in column.
Or as a one liner:
outputmatrix = cell2mat(arrayfun(@myprogram, [8 9], 'UniformOutput', false)');
댓글 수: 0
Andrew Reibold
2014년 8월 21일
편집: Andrew Reibold
2014년 8월 21일
Here is a sure-fire but not necessarily efficient way. This should combine the results of generating lots of 2x2 matrices that are just whatever number d is.
Replace my A with how to solve for yours, and you are good to go. :)
for d = 1:10 % Change this to however many d's you want to go through
A = d*ones(2,2); %Replace this with however you generate A
combined_results(2*d-1,1) = A(1,1);
combined_results(2*d-1,2) = A(1,2);
combined_results(2*d,1) = A(2,1);
combined_results(2*d,2) = A(2,2);
end
combined_results
댓글 수: 0
Joseph Cheng
2014년 8월 22일
just perform the standard concatenation of
Results = [];
for d=8:9
Results = [Results; your_function(d)];
end
which you stick your function results at the end of results.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!