Borrar filtros
Borrar filtros

[l m]=a(1,2,3;6,7,8) in matlab..........

8 visualizaciones (últimos 30 días)
KALYANAPU  SRINIVAS
KALYANAPU SRINIVAS el 10 de Mayo de 2017
Comentada: Stephen23 el 10 de Mayo de 2017
is it possible to assign the elements of matrix a to [l m]?
  2 comentarios
KALYANAPU  SRINIVAS
KALYANAPU SRINIVAS el 10 de Mayo de 2017
in the above question l=a[i][j] value i.e l=1 and m=a[i][j+1] value i.e m=6; and so on..... is the required answer. Please provide the code if exist
Jan
Jan el 10 de Mayo de 2017
The question is not clear and the comment confuses me even more. What is "a[i][j]"? It is no valid Matlab syntax, but please do not let us guess if you mean C code or any other notation. Explain clearly what you want to get. "m=a[i][j+1] value i.e m=6"???

Iniciar sesión para comentar.

Respuestas (1)

KL
KL el 10 de Mayo de 2017
  1. You cannot assign two variables in one command unless it's a function return.
  2. To define an array you should use "Square braces" --> [ ]
  3. Then if you want to access the elements of a matrix, it goes like matrix_name(rowIndex, columnIndex))
For your case,
>> a = [1,2,3;6,7,8]
a =
1 2 3
6 7 8
>> l = a(1,1)
l =
1
>> m = a(2,1)
m =
6
In case you want all the values in the first row on l and second row on m, then
>> l = a(1,:)
l =
1 2 3
>> m = a(2,:)
m =
6 7 8
here : means all elements in the specified rowIndex.
  3 comentarios
KL
KL el 10 de Mayo de 2017
Thanks for the links Stephen. Yes, I'm familar with cell array returns while accessing its contents (as opposed to matrices). I'm just wondering, does it really make a difference calling it array concatenation? after all, we're creating a new array by using the square brackets, I think. Having said that, I appreciate you pushing people learn the better way.
Stephen23
Stephen23 el 10 de Mayo de 2017
"does it really make a difference calling it array concatenation?"
We regularly get questions here where people want to create lists (which MATLAB does not have), and they often mistake the [] operator for a list operator. It does cause some confusion for them. I believe that clarifying the concatenation role helps beginners to understand that all numeric values are arrays (even scalar arrays (aka "numbers")), as arrays are a first-class type in MATLAB.
So while the difference might be subtle and small, I think it is a point that is worth making, in order to understand MATLAB better.

Iniciar sesión para comentar.

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by