I have this problem
Show older comments
I have a column vector
k =[ 0 0 0 0 0 0 2 5 6 8 7 2 1 0 0 0 0 3 5 4 1 8 6 8 ];
I want to keep the shape of the vector while replacing every 1st and 3rd non zero element with 100 so I end up with
k = [ 0 0 0 0 0 0 100 5 6 8 100 100 1 2 5 100 0 100 5 4 1 100 6 8];
2 Comments
Rik
on 19 Sep 2018
How are you counting? I can't reproduce your vector by any way I can think of
% 1 2 3 1 2 3 1 1 2 3 1 2 3 1
% 1 2 3 1 2 3 1 2 3 1 2 3 1 2
% (1 2 3 1 2 3)1 2 3 1 2 3 1(2 3 1 2)3 1 2 3 1 2 3
k=[ 0 0 0 0 0 0 2 5 6 8 7 2 1 0 0 0 0 3 5 4 1 8 6 8 ];
% x x x x x x x x x x
% x x x x x x x x x
% x x x x x x x x x x
None of these patterns result in your second vector. Also, there seem to be some extra values. Please explain what your pattern is, then we can try to help you find a way to implement it.
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements 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!