What is the elegent way to replace every Nth column in a matrix with another column?
Show older comments
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 Comments
Azzi Abdelmalek
on 23 Nov 2012
What do you mean by with another column? which one?
Daniel Shub
on 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
on 23 Nov 2012
Accepted Answer
More Answers (1)
indices = n:n:size(A,2);
A(:,indices)=v(:,ones(size(indices)));
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!