MATLAB Answers

How to break or split a line at NaN points in 1x15000 csv file?

2 views (last 30 days)
Roobini Vijayabalan
Roobini Vijayabalan on 21 Oct 2019
Commented: Yuan Li on 24 Oct 2019
i have a csv file (1x15000) which needs to be splitted at specific points(NaN).

  0 Comments

Sign in to comment.

Answers (1)

Yuan Li
Yuan Li on 21 Oct 2019
You can start with finding the position of NaN, for example:
a is your loaded data array;
then use
[m,n]=find(isNaN(a));
you can locate the position of NaN, then you can use the locations to split the array.

  4 Comments

Show 1 older comment
Yuan Li
Yuan Li on 21 Oct 2019
for example, if a=[1,2,3,4,NaN,5,6,7,8,NaN,9,10];the position is p=[5,10];then, use for loop:
temp = zeros(length(p)+1,length(a));%use a big matrix to save data since each row may have different length
for ii = 1:length(p)+1
if ii == 1
temp(ii,1:p(ii)-1) = a(1:p(ii)-1);
elseif ii == length(p)+1
temp(ii,1:length(a)-p(ii-1)) = a(p(ii-1):end);
else
temp(ii,1:p(ii)-p(ii-1)-1) = a(p(ii-1)+1:p(ii)+1);
end
end
Roobini Vijayabalan
Roobini Vijayabalan on 21 Oct 2019
ya thanks for the help
how to break the line after every NaN to create a new column?

Sign in to comment.


Translated by