Borrar filtros
Borrar filtros

what does x= [ones(1,2) 2 ones(1,1) 2 ones(1,2) 1] do?

3 visualizaciones (últimos 30 días)
Prb
Prb el 8 de Mayo de 2019
Comentada: Prb el 14 de Mayo de 2019
please explain the X= [ones(1,2) 2 ones(1,1) 2 ones(1,2) 1];
line of code. I understand that it is creating 1 by 2 array of ones. But what is the significance of 2 ones(1,1) and so on.

Respuesta aceptada

KSSV
KSSV el 8 de Mayo de 2019
It depends on the requirement of what array you want. If you see that line generates:
[1 1 2 1 2 1 1 1]
The array has 2 in 3rd, 4th position. So 2 is used. The same can also be generated using:
X = ones(1,8) ;
X([3 5]) = 2

Más respuestas (0)

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