print the element of a matrix

조회 수: 156 (최근 30일)
mohammed almakaleh
mohammed almakaleh 2020년 5월 17일
편집: mohammed almakaleh 2020년 5월 17일
i wrote this code to print the largest element in the first row of a matrix, but it print the index of the largest number?
how cam i print largest element??
matrix=input("Enter the Matrix");
max=0;
[r,c]=size(matrix);
d=c[j];
n=length(matrix);
for i=0:1
for j=0:c
if [j]> max
max=[j];
end
end
end
disp(max);

채택된 답변

Stijn Haenen
Stijn Haenen 2020년 5월 17일
You can use:
a=max(matrix(1,:));
disp(a)
to disp the max value from the first row,
or
b=max(matrix(:,1));
disp(b)
to get the max value from the first column
you can use
[a,x]=max(matrix(1,:));
to get the value and the positions of the max element.
  댓글 수: 1
mohammed almakaleh
mohammed almakaleh 2020년 5월 17일
thanj you for hlep
is the any way to print it with out using (max) function?

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

추가 답변 (1개)

Stijn Haenen
Stijn Haenen 2020년 5월 17일
a=-Inf;
for i=1:numel(matrix(:,1))
if matrix(i,1)>a;
a=matrix(i,1);
end
end
disp(a)
  댓글 수: 1
mohammed almakaleh
mohammed almakaleh 2020년 5월 17일
편집: mohammed almakaleh 2020년 5월 17일
thanx a lot

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by