필터 지우기
필터 지우기

making answer into array

조회 수: 1 (최근 30일)
God'sSon
God'sSon 2011년 3월 28일
How can I concatenate my answers from a for-loop into an array. consider this example:
a=[2 1 3 1
1 4 1 5
6 7 1 1
8 1 9 1];
for i=(1:4)
row=(a(i,:));
b=sort(row)
end
I need an answer which is (b= 4x4 array) like the original (a)
cheers.

채택된 답변

Oleg Komarov
Oleg Komarov 2011년 3월 28일
Are you trying to do:
a = [2 1 3 1
1 4 1 5
6 7 1 1
8 1 9 1];
sort(a,2)
ans =
1 1 2 3
1 1 4 5
1 1 6 7
1 1 8 9
  댓글 수: 2
God'sSon
God'sSon 2011년 3월 28일
yes, but I have a series of expressions in a for-loop to execute.
Oleg Komarov
Oleg Komarov 2011년 3월 28일
Even if you were to store the answer progressively into b, you will always have to reference it, thus I suggest to move the sort operation outside the loop...even better would be to post the operation you want to perform inside the loop, maybe it is avoidable.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by