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."
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!