generating a matrix with 2 coordinates

1 次查看(过去 30 天)
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 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by