MATLAB Answers

Line, Column and Magnitude in a matrix.

3 views (last 30 days)
Ricardo Gutierrez
Ricardo Gutierrez on 28 Oct 2019
Commented: Ricardo Gutierrez on 28 Oct 2019
Hello good day.
I want to find a code that indicates the Line, Column and Magnitude of an element of an array. For which I have prepared the following code:
% ____________________________________________
clc; clear; close all; short format
N = 3;
vctrs = [1 12 14
       12 51 14
       17 81 91
       19 10 12
       15 2 33
       16 17 18
       13 21 13
       15 31 3];
    [val, pos] = min (vctrs);
   for b = 1: 1: N
     Value (b) = val (1, b)
     [line (b), column (b)] = find (vctrs == Value (b))
end
% ____________________________________________________
This code gives me the result:
Value =
     1 2 3
line =
     1 5 8
column =
     1 2 3
Which I am looking for, but if I repeat any of those minimum values ​​in any line or column it marks the following error:
_________________________________________________
In an assignment A (I) = B, the number of elements in B and I must be the same.
Error in practice2 (line 16)
     [line (b), column (b)] = find (vctrs == Value (b))
___________________________________________________
The magnitudes that form the matrix are constantly changing and sometimes it does not show me this error, but this is not sure.
I would like the code to indicate the minimum magnitude per column as well as its position and if in a single column there are two or three repeated minimums that only mark the position and magnitude of the first minimum value of that column.
I hope you help me.
Regards.

  3 Comments

Alex Mcaulley
Alex Mcaulley on 28 Oct 2019
What is wrong with this?
vctrs = [1 12 14
12 51 14
17 81 91
19 10 12
15 2 33
16 17 18
13 21 13
15 31 3];
[val, pos] = min (vctrs)
val =
1 2 3
pos =
1 5 8
darova
darova on 28 Oct 2019
Function min already returns number of line/row in pos variable, val - magnitude
[val, pos] = min(vctrs);
Ricardo Gutierrez
Ricardo Gutierrez on 28 Oct 2019
Hello
Good morning.
Your answer is very helpful
Thank you.

Sign in to comment.

Answers (0)