remove elements...and save in another vector...
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Image Analyst
2014 年 8 月 11 日
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?
回答 (1 件)
dpb
2014 年 8 月 11 日
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 件のコメント
dpb
2014 年 8 月 12 日
I quote from my initial posting -- "Not fully developed". A quick example to get the creative juices flowing...
参考
カテゴリ
Help Center および File Exchange で Particle Swarm についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!