Removing NaN from matrix
4 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (2 件)
Hikaru
2014 年 7 月 29 日
If all columns contain n rows of NaN values, then you could remove them by using:
temp(isnan(temp(:,1)),:) = []
0 件のコメント
Patrik Ek
2014 年 7 月 29 日
編集済み: Patrik Ek
2014 年 7 月 29 日
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Splines についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!