Hi,
This is the matrix I obtained
K = 8 16 -16 -8 -16 16 -20 -40 40 18 2 -6 -18 -2 6 -45 -5 15 12 20 20 -12 -20 -20 -30 -50 -50 -4 -8 8 4 8 -8 0 0 0 -9 -1 3 9 1 -3 0 0 0 -6 -10 -10 6 10 10 0 0 0 -16 -32 32 -8 -16 16 0 0 0 -36 -4 12 -18 -2 6 0 0 0 -24 -40 -40 -12 -20 -20 0 0 0
The question asked me to find the maximum number and it's location using the max function. I did this by using this code:
max_num=max(K(:)) [X Y]=ind2sub(size(K),max_num)
From the code, I got the maximum value off from the matrix, however the location is not right.
max_num = 40X = 4Y = 5
The X and Y should have display X = 9 , Y = 1 , instead it displays X = 4 , Y = 5. I don't know what is wrong with my code. It would be great if anyone can help me with this.
Thank you in advance.
Best Answer