How to assign parts of a matrix equal to a single vector
Mostrar comentarios más antiguos
In matlab if you had a vector called y = ones(5,5), you could do the following assignments:
y(:,1) = 0; First column in all rows equals zero.
y(:,1:2) = 0; First two columns in all rows equals zero.
y(1,:) = 0; First row equals zero, etc.
But what if you wanted to be more specific, say for example I had a vector x = [0 2 0] and I wanted y(2:4,2:4) = x; Meaning the middle 3 columns and middle 3 rows would be set to that vector. The problem is it doesn't accept this kind of assignment and gives a "Subscripted assignment dimension mismatch" error. I was wondering if there is any way to do this, or this something like this only possible through a for loop?
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Operators and Elementary Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!