- On the RHS square brackets are a concatenation operator (not a "list" operator, which MATLAB does not have). So your RHS concatenates some arrays together into one array, and is equivalent to this: D([1:2,2:10])
- On the LHS square brackets are used to capture multiple function outputs. However array concatenation only returns one output, so the code you show will not work: one output cannot be directly assigned to three outputs.
I want to assign multiple arrays of data simultaneously to different variable
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
TM Abir Ahsan
el 2 de Jun. de 2022
Comentada: TM Abir Ahsan
el 2 de Jun. de 2022
I want to assign multiple arrays of data simultaneously to different variable, but I think my syntax is wrong, Can anybody help me out here? A simple version of the code is gioven below.
D=[1 2 3 4 5 6 7 8 9 10];
[p q r]= [D(1:2) D(2:5) D(6:10)]
2 comentarios
Stephen23
el 2 de Jun. de 2022
Editada: Stephen23
el 2 de Jun. de 2022
"I want to assign multiple arrays of data simultaneously to different variable, but I think my syntax is wrong"
It looks as if you are trying to write Python code. If you want to understand what your MATLAB code is actually doing:
Square brackets are used a lot in MATLAB, you need to understand what they mean and how to use them:
Respuesta aceptada
Más respuestas (0)
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!