Multiplying even and odd columns separately?
9 views (last 30 days)
Show older comments
I have a matrix called 'displacements'
It has 50 columns
I want to multiply all the even columns by 5 and all the odd columns by 8
Anyone know a quick way to do this?
0 Comments
Answers (2)
Giorgos Papakonstantinou
on 6 Mar 2015
Here is one way:
A =rand(100, 50);
idx = mod(1:size(A,2), 2) ==1; % logical indexing of the odd numbers
theodd = A(:, idx)*8;
theeven = A(:, ~idx)*5;
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!