Tags: delete, folks, matlab, programming, this0, vector, vectors
delete data from vectors
On Programmer » Matlab
1,385 words with 1 Comments; publish: Sat, 26 Apr 2008 21:17:00 GMT; (20046.88, « »)
Hi Folks.
I need your help.
I have a Vector some like this:
[0 1 2 3 4 5 0 2 3 4 0 4 5 6 0 6 4 0 3 5 6 7 0 0 0 0 0 ]
Now I want to delete e.g. everything between the 2nd and 3rd 0 (Zero) and fo
r example between the 5th and 6th.
So the new Vector looks like this:
[0 1 2 3 4 5 0 4 5 6 0 6 4 0 0 0 0 0 ]
Best regards.
Walter
http://matlab.itags.org/q_matlab_12588.html
All Comments
Leave a comment...
- 1 Comments

- Hello,
I have another answer. You can test which one is faster.
v=[0 1 2 3 4 5 0 2 3 4 0 4 5 6 0 6 4 0 3 5 6 7 0 0 0 0 0]; %your vektor
d=[2,3;5,6]; % delete from 2nd zero to 3rd, 5th to 6th
z=find(v == 0); %find all zeros in a
for i = 1:size(d,1)
v(z(d(i,1)):(z(d(i,2))-1)) = NaN;
end
v(isnan(v)) = []; %delete all NaN in vektor v
Best regards.
Andrea
"walli_wuff" <linze.matlab.itags.org.web.de> schrieb im Newsbeitrag news:29703519.1177268776790.JavaMail.jak
arta.matlab.itags.org.nitrogen.mathforum.org...
> Hi Folks.
>
> I need your help.
>
> I have a Vector some like this:
>
> [0 1 2 3 4 5 0 2 3 4 0 4 5 6 0 6 4 0 3 5 6 7 0 0 0 0 0 ]
>
> Now I want to delete e.g. everything between the 2nd and 3rd 0 (Zero) and
for example between the 5th and 6th.
> So the new Vector looks like this:
>
> [0 1 2 3 4 5 0 4 5 6 0 6 4 0 0 0 0 0 ]
>
> Best regards.
> Walter
#1; Sat, 26 Apr 2008 21:19:00 GMT