How do you use the NaN function?

How would write a code that for a vector that is 500 data points long, but the first 123 data points are NaN?

Réponses (1)

Abdolkarim Mohammadi
Abdolkarim Mohammadi le 14 Sep 2020
Modifié(e) : Abdolkarim Mohammadi le 14 Sep 2020

0 votes

You first create the NaN vector using nan(), then fill in the elements.
V = nan (500,1);
V (124:end) = Data;

4 commentaires

Nicholas Deosaran
Nicholas Deosaran le 14 Sep 2020
wont that just make all 500 data points nan?
Just need to know how to make the 1st 124 nan and the rest 125-500...
Abdolkarim Mohammadi
Abdolkarim Mohammadi le 14 Sep 2020
Modifié(e) : Abdolkarim Mohammadi le 14 Sep 2020
The first line create the NaN vector and the second line fills it with your data. You may feel more comfortable with this syntax:
V (1:123) = NaN;
I am still not understanding
the code will be like
v = (500,1)
data = (1:123)=nan
is that right or no?
No. If you have your vector of values for 125 to 500 and you want to transfer them to the new vector, then you should use:
V = nan (500,1);
V (124:end) = Data;
Otherwise, if you have a 500 element vector and you want to eliminate the first 125 elements, then you can do it in one command (not the one you mentinoed):
Data (1:123) = NaN;

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by