output of indices column or row vector
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Rick
el 2 de Ag. de 2014
Respondida: Geoff Hayes
el 2 de Ag. de 2014
A = [5 6];
EDU>> B = [3;4];
EDU>> C = 3;
EDU>> B(2) = 2;
EDU>> B(:,2) = A'
B =
3 5
2 6
EDU>> B = B - C
B =
0 2
-1 3
EDU>> t = A*B
t =
-6 28
EDU>> t = [t; B(2,:)];
EDU>> [i,j] = find(t>0)
i =
1
2
j =
2
2
I was wondering, why do i and j come out as column arrays, and not row arrays??
0 comentarios
Respuesta aceptada
Geoff Hayes
el 2 de Ag. de 2014
ind = find(X) locates all nonzero elements of array X, and returns the linear indices of those elements in vector ind. If X is a row vector, then ind is a row vector; otherwise, ind is a column vector. If X contains no nonzero elements or is an empty array, then ind is an empty array.
The text doesn't really say what will happen if the input is a matrix. I tried a couple of examples for square matrices, ones with more rows than columns, ones with more columns that rows. The result each time included two column vectors. So this may just be the default behaviour for when the input is a matrix.
Why were you expecting row vectors/arrays?
0 comentarios
Más respuestas (2)
Image Analyst
el 2 de Ag. de 2014
Because MATLAB stores arrays in memory in that order, column major order. It's just the way they chose to design the language.
0 comentarios
Azzi Abdelmalek
el 2 de Ag. de 2014
Editada: Azzi Abdelmalek
el 2 de Ag. de 2014
Your question should be like this
t = [-6 28; -1 3]
[i,j] = find(t>0)
i =
1
2
j =
2
2
I was wondering, why do i and j come out as column arrays, and not row arrays??
Because the previous calculations have nothing to do with your question. And i are j are displayed as columns, because Matlab has to display them as columns or rows, it's not important if they are displayed as column or as rows, because the most important thing is to know the position (i,j) of the elements in t that match the conditions.
0 comentarios
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!