Removing NaN from matrix

4 visualizaciones (últimos 30 días)
Eric
Eric el 22 de Jul. de 2014
Editada: Patrik Ek el 29 de Jul. de 2014
Hi,
I have a loop that stores data for each trial into a temp variable called temp(:,tnum).
The trials are of unequal row length. At the end of the trials (tnum), there is a NaN for n number of rows.
I would like to remove the NaN from each trial. Ultimately, regardless of the length of the trial I need to normalize each trial to 100 data points in order to take the ensemble average of the 5 trials.
for tnum = 1:5
temp(:,tnum) = DATA.(subjs{s}).(trial)(tnum).(jnt{j}).(var{v}).(dir{d}).data;
templin(:,tnum) = linspace(0,100,(size(temp(:,tnum),1)))';
xaxis = linspace(0,100,100)';
tempnorm(:,tnum) = spline(temlin(:,tnum),temp(:,tnum),xaxis);
end
This code run but I get a warning Warning: All data points with NaN in their value will be ignored. > In polyfun\private\chckxy at 101 In spline at 54
However, the last 20 or 30 of the 100 data points of
tempnorm(:,tnum) are not correct.
If anyone could me with my issue, I would greatly appreciate it.
Eric

Respuestas (2)

Hikaru
Hikaru el 29 de Jul. de 2014
If all columns contain n rows of NaN values, then you could remove them by using:
temp(isnan(temp(:,1)),:) = []

Patrik Ek
Patrik Ek el 29 de Jul. de 2014
Editada: Patrik Ek el 29 de Jul. de 2014
You could choose to only pass non nan elements to spline.
nonNanTemlin = ~isnan(temlin(:,tnum));
tempnorm(:,tnum) = spline(temlin(nonNanTemlin,tnum),temp(nonNanTemlin,tnum),xaxis);
However, would it not be better with a weighted average here? From what I remember of statistics, that is the correct way of do this. Interpolating does not necessarily make the variance lower.

Categorías

Más información sobre Splines en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by