What does the following code do?

조회 수: 2 (최근 30일)
daniel
daniel 2022년 12월 26일
답변: Voss 2022년 12월 26일
clear all
close all
clc
M=1; n=0;
while or(M~=0,length(M(:))~=1)
M=input('Enter matrix: ');
if and(M==0,length(M(:))==1)
break
end
n=n+1;
MM{n}=M;
S(n)= sum(M(:));
end
[SS,ind]= sort(S);
Mtmp=MM;
for ii=1:n
MM{ii}=Mtmp{ind(ii)};
end
celldisp(MM);
  댓글 수: 2
John D'Errico
John D'Errico 2022년 12월 26일
Talk to the source of the code Asing what uncommented junk code does is difficult to say, especially if we are given no clue as to what it is supposed to do. And, sorry, but this is junk code.
daniel
daniel 2022년 12월 26일
Sorry I fixed the code

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

채택된 답변

Voss
Voss 2022년 12월 26일
This code prompts the user to input a sequence of matrices (input a scalar 0 to stop) and sorts the matrices according to the sum of their elements.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by