Extract a portion of vector
11 ビュー (過去 30 日間)
古いコメントを表示
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 件)
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
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."
Jonathan Epperl
2012 年 10 月 22 日
How about
vector(vector(:,1)<20, 2) = NaN;
Logical indexing...
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!