What is the elegent way to replace every Nth column in a matrix with another column?
Afficher commentaires plus anciens
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 commentaires
Azzi Abdelmalek
le 23 Nov 2012
What do you mean by with another column? which one?
Daniel Shub
le 23 Nov 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
le 23 Nov 2012
Réponse acceptée
Plus de réponses (1)
indices = n:n:size(A,2);
A(:,indices)=v(:,ones(size(indices)));
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!