Info
此问题已关闭。 请重新打开它进行编辑或回答。
I want to arrange the first column of a matrix in ascending order. But my Code is not showing the correct value.
1 次查看(过去 30 天)
显示 更早的评论
>> A = [15 4; 3 -1; 10 78; -9 101];
>> t=A; % Temporary matrix
>> B= zeros([4,2]); % Output Matrix
>> for i=4:1
MAX_NUM = max(A(1:i,1));
[ROW_NUM, COL_NUM] = find(A==MAX_NUM);
B(i,1:2) = A(ROW_NUM,1:2);
A(ROW_NUM,1:2) = A(i,1:2);
i = i-1;
end
>> A=t;
>> disp(B)
0 0
0 0
0 0
0 0
0 个评论
回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!