フィルターのクリア

Extract a portion of vector

12 ビュー (過去 30 日間)
Alessandro Antonini
Alessandro Antonini 2012 年 10 月 22 日
Hi, I have a problem that I can not solve.
I need to extract a portion of my vector, this vector has 2 columns (first column is time and second is wave height) and 2500 rows, the values of the second column are number and NaN, the data are sampled every 3 hours. The problem is: I need to create a new vector that contains only the registration longer than 20 hours, and for the rest I must to replace with NaN.
Here an example:
Initial vector= [0 0.2
3 0.35
6 NaN
9 NaN
12 NaN
15 NaN
18 NaN
21 NaN
24 0.29
27 0
30 0
33 0
36 0
39 0
42 0
45 0.18
48 0.33
51 NaN
54 NaN
57 NaN]
The result should be
[0 NaN
3 NaN
6 NaN
9 NaN
12 NaN
15 NaN
18 NaN
21 NaN
24 0.29
27 0
30 0
33 0
36 0
39 0
42 0
45 0.18
48 0.33
51 NaN
54 NaN
57 NaN]
Can anyone suggest an approach to solve this problem?
Thanking you in advance
Alessandro Antonini
  3 件のコメント
Alessandro Antonini
Alessandro Antonini 2012 年 10 月 22 日
No, * doesn't mean anything. I tried to write in bold the first two rows of the vector and * it appeared. It is wrong, there is not any *.
Walter Roberson
Walter Roberson 2012 年 10 月 22 日

サインインしてコメントする。

採用された回答

Alessandro Antonini
Alessandro Antonini 2012 年 10 月 22 日
I solve the problem with the help of my friend, I needed two while cicle.
to solution was:
C=impuct vector and e1=C(:,2), the code is:
i=1;
while i<length(e1)
j=0;
i
while isnan(e1(i+j))==0 && (i+j)<length(e1)
j=j+1;
end
if j<7
e1(i:(i+j-1))=NaN;
end
i=i+j+1;
end

その他の回答 (3 件)

Matt Fig
Matt Fig 2012 年 10 月 22 日
編集済み: Matt Fig 2012 年 10 月 22 日
Say this is your vector:
A = [3 4;5 6;8 7;9 8;7 5;5 3;3 9;12 4];
And you want all rows from 5 to the end to be nan:
A(5:end,:) = nan;
  2 件のコメント
Matt Fig
Matt Fig 2012 年 10 月 22 日
編集済み: Matt Fig 2012 年 10 月 22 日
Alessandro comments:
"no, I think is different. This is my imput: A=[0 0.3; 3 23; 6 NaN; 9 NaN; 12 NaN; 15 NaN; 18 NaN; 21 NaN; 24 0.29; 27 0; 30 0; 33 0; 36 0; 39 0; 42 0; 45 0.18; 48 0.33; 51 NaN;]
The output should be: B=[0 NaN; 3 NaN; 6 NaN; 9 NaN; 12 NaN; 15 NaN; 18 NaN; 21 NaN; 24 0.29; 27 0; 30 0; 33 0; 36 0; 39 0; 42 0; 45 0.18; 48 0.33; 51 NaN;] In which, the position (1,2) and (2,2), becomes NaN, because I need to take into account only the registration more long than 20 hours. The hours are in the first column. As it can be noticed in the vector B, from position (9,2) till (17,2) the values are the same than in vector A, because the registration is longer than 20 hours. I am sorry for my poor exposition, I hope that this can help to understand my problem."
Matt Fig
Matt Fig 2012 年 10 月 22 日
編集済み: Matt Fig 2012 年 10 月 22 日
So you simply use the same concept....
B = A; % Make a copy
B(B(:,1)<=20,2) = nan

サインインしてコメントする。


Alessandro Antonini
Alessandro Antonini 2012 年 10 月 22 日
編集済み: Alessandro Antonini 2012 年 10 月 22 日
I need to take into account only the partial measure more long than 20 hours, that is if I have a vector like that:
A=[0 2;
3 NaN;
6 3;
9 NaN;
12 4;
15 NaN;
18 5;
21 NaN;
24 6;
27 NaN;
30 7;
33 NaN;
36 8;
39 NaN;
42 9;
45 NaN;
48 10;
51 NaN;]
the result will be:
A=[0 NaN;
3 NaN;
6 NaN;
9 NaN;
12 NaN;
15 NaN;
18 NaN;
21 NaN;
24 NaN;
27 NaN;
30 NaN;
33 NaN;
36 NaN;
39 NaN;
42 NaN;
45 NaN;
48 NaN;
51 NaN;]
I need to consider only if the partial and continues duration is more long than 20 hours, as in the sequent vector from row n°4 to row n° 11, (partial duration of the registration (C(1,11)-C(1,4))=30-9=21 hours), only in this case I need to take into account. All the other values registered I don't want to take into account, they should be replaced with NaN
C=[0 0.3
3 23
6 NaN
9 0.2
12 0.53
15 0.7
18 0.1
21 0.02
24 0.53
27 0.18
30 0.25
33 NaN
36 NaN
39 NaN
42 NaN
45 NaN
48 0.33
51 NaN]
If the vector C is the imput, the result of the operation should be (vector D):
D=[0 NaN;
3 NaN;
6 NaN;
9 0.2;
12 0.53;
15 0.7;
18 0.1;
21 0.02;
24 0.53;
27 0.18;
30 0.25;
33 NaN;
36 NaN;
39 NaN;
42 NaN;
45 NaN;
48 NaN;
51 NaN];
In which, the values in the position D(1,2) and D(2,2) now are NaN, because the partial duration of the registration (continues and different from NaN)is lower than 20 hours, i.e. C(2,1)-C(1,1)=3-0=3.
At the end, the goal would be, take into account only those values registered that have a continuous registration more long than 20 hours.

Jonathan Epperl
Jonathan Epperl 2012 年 10 月 22 日
How about
vector(vector(:,1)<20, 2) = NaN;
Logical indexing...

カテゴリ

Help Center および File ExchangeTiming and presenting 2D and 3D stimuli についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by