generating a matrix with 2 coordinates

조회 수: 3 (최근 30일)
Umut Oskay
Umut Oskay 2020년 4월 17일
댓글: Walter Roberson 2020년 4월 18일
m = input('Enter a number of row (m):'); % Number of rows
n = input('Enter a number of columns (n):'); % Number of Columns
M = randi(100,[m,n]) % It generates random Matrix with the size of m x n
min = inf;
max = 0;
for a = 1:m
for b = 1:n
if M(a,b) < min
min = M(a,b);
mina = a;
minb = b;
end
if M(a,b) > max
max = M(a,b);
maxa = a;
maxb = b;
end
end
end
fprintf('Min is %d at:%d,%d\n',min,mina,minb);
fprintf('Max is %d at:%d,%d\n',max,maxa,maxb);
for c = mina:maxa
for d = minb:maxb
if M(c,d) >= 0
M(c,d) = -M(c,d);
end
end
end
in this code i found the min and the max in the array but i have to generate a matrix with this M(mina,minb) and M(maxa,maxb). These coordinates should be the corners of the matrix.How can i do it can you help me ? By the way there shouldnt be any built in functions. Thanks
  댓글 수: 5
Umut Oskay
Umut Oskay 2020년 4월 17일
Hmm okey. There should be some way to do it . In the previous part you said the same thing but somebody did it well.Thanks
Walter Roberson
Walter Roberson 2020년 4월 18일
Incorrect. James' solution violated the rules about not using built-in functions, and you should have rejected his solution. I responded there listing exactly the names of the built-in functions that were called. Do I need to link to their individual documentation pages to prove that they are functions?
https://www.mathworks.com/help/matlab/ref/subsref.html
Read it. It says explicitly that the function is called to implement indexing.
IN MATLAB IT IS IMPOSSIBLE TO INDEX WITHOUT USING THE FUNCTION NAMED subsref. subsref is a built in function. If your program contains even one subscript use, then it uses a built-in function, which violates the rules of the assignment.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Customize Object Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by