What is the elegent way to replace every Nth column in a matrix with another column?
Mostrar comentarios más antiguos
It looks easy with a for loop, but I am a beginner and was told to try and avoid for loops...
I though abot something that looks like A(;,n:n:end) but I get a "dimensions mismatch error"
Thank you
3 comentarios
Azzi Abdelmalek
el 23 de Nov. de 2012
What do you mean by with another column? which one?
Daniel Shub
el 23 de Nov. de 2012
You A(:, n:n:end) looks like the way to go. Without the actual code and variables, we are left to guess. Please tell us the size of A, the value of n, and the size of this "other" column.
tamirmal
el 23 de Nov. de 2012
Respuesta aceptada
Más respuestas (1)
indices = n:n:size(A,2);
A(:,indices)=v(:,ones(size(indices)));
Categorías
Más información sobre Resizing and Reshaping Matrices en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!