Dear Matlab community,
I am trying to set a certain array within a vector = NaN
Example:
If I have a vector with a dimension 9,1:
0.0001
0.0003
0.0001
0.0002
2
3
4
5
6
And I would like to set the elements 1-4 = NaN, to get the following output:
NaN
NaN
NaN
NaN
2
3
4
5
6
Does someone know how to set an array within the vector to NaNs? In this case, I know that element 1-4 should be NaNs.
Thank you very much!
Chris

 採用された回答

Star Strider
Star Strider 2015 年 9 月 11 日

0 投票

This will do what you want:
V = [0.0001
0.0003
0.0001
0.0002
2
3
4
5
6];
V(V<1) = NaN

4 件のコメント

Christoph Meier
Christoph Meier 2015 年 9 月 11 日
Thank you very much for your suggestion! I am looking for a way to set a specific array to NaNs, as my actual vector also fluctuates around zero.
Sorry for being not specific enough.
Star Strider
Star Strider 2015 年 9 月 11 日
What are the characteristics of your data that you want to set to NaN? It would likely require only a minor change (such as adding one of more conditions) in the logic in my code.
Christoph Meier
Christoph Meier 2015 年 9 月 11 日
I found a solution to the problem myself, and I will share for other users:
Setting a specific array within a vector = NaN, or any other value for that purpose:
V = [0.0001
0.0003
0.0001
0.0002
2
3
4
5
6];
V(1:4) = NaN
V = [NaN
NaN
NaN
NaN
2
3
4
5
6];
Thank you, Star Strider!
Star Strider
Star Strider 2015 年 9 月 11 日
My pleasure.
I thought you wanted to set specific conditions on what elements became NaN.

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

その他の回答 (0 件)

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by