generating a matrix with 2 coordinates

1 view (last 30 days)
Umut Oskay
Umut Oskay on 17 Apr 2020
Commented: Walter Roberson on 18 Apr 2020
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 Comments
Umut Oskay
Umut Oskay on 17 Apr 2020
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 on 18 Apr 2020
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.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!