remove elements...and save in another vector...
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have column vector like this P=[ 0;455.444; 326.416; 333.008; 200.806; 273.315; 267.822; 268.066;0 ; 457.153; 206.177; 282.349; 0; 450.806; 187.378; 265.869; 264.648; 266.357; 0; 444.336; 331.177; 333.374; 204.224; 255.981; 0 ;452.271; 322.388; 325.562; 193.726; 276.123; 0; 442.749; 178.955; 260.376; 0; and so on....]; Its corresponding T = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; 13; 14; 15; 16; 17; 18; 19; 20; 21; 22; 23; 24; 25; 26; 27; 28; 29; 30; 31; 32; 33; 34 ; and so on....];
I want to keep only 1st element from 0 element and last two non zero element before another O element (shown in bold). So LENGTH BETWEEN TWO 0 (the left 0 and right 0) is 3. Save 2nd position elements in P2 column vector and 3rd position elements in P3 column vector. 3rd position element in P4, 5th element in P5. The result should be
After extraction, the remaining elements should be placed into P1 such as
P1 = P=[ 0;455.444; 267.822; 268.066;0 ; 457.153; 206.177; 282.349; 0; * 450.806; 264.648; 266.357; 0; 444.336; 204.224; 255.981; 0 ;452.271; 193.726; 276.123; 0; 442.749; 178.955; 260.376; 0; and so on....]; P2= [ 326.416;206.177; 187.378; 331.177;322.388]; P3=[333.008;265.869; 331.177] P4=[200.806]; P5=[273.315]; and it corresponding T in T1; T2;T3;T3;T5
i tried using Pzeros = find(P == 0); violators = Pzeros(find(Pzeros(2 : end) - Pzeros(1: end - 1) > 4)); P1 = P; P1([violators + 2; violators + 3; violators + 4; violators + 5]) = []; P2 = P(violators + 2); P3 = P(violators + 3); P4 = P(violators + 4); P5 = P(violators + 5);
but facing some problem
2 commentaires
Image Analyst
le 11 Août 2014
Then why did you accept that answer? And why didn't you follow up with that answer in http://www.mathworks.com/matlabcentral/answers/146887#answer_147951?
Réponses (1)
dpb
le 11 Août 2014
Not fully developed, but how about working from the following...
>> pz=reshape(find(P==0),2,[]).'
pz =
1 9
13 19
25 31
>> cell2mat(arrayfun(@(ix,iy) [P(ix:ix+1);P(iy-2:iy-1)],pz(:,1),pz(:,2),'uniform',0))
ans =
0
455.4440
267.8220
268.0660
0
450.8060
264.6480
266.3570
0
452.2710
193.7260
276.1230
>>
2 commentaires
dpb
le 12 Août 2014
I quote from my initial posting -- "Not fully developed". A quick example to get the creative juices flowing...
Voir également
Catégories
En savoir plus sur Cell Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!