I have a vector where the end is padded with NaN. How to index where real numbers end and where NaNs begin
4 次查看(过去 30 天)
显示 更早的评论
Dear Matlab,
Attached is sample data with a row vector.
The row vector is an averaged EEG signal and starts with real numbers and at some point, the real numbers end and the NaNs begin. I want to find where (what column) the NaNs start so that I can trim the NaNs and just have a vector of real number values. Please help/advice.
Thanks in advance!
Joanne
0 个评论
采纳的回答
the cyclist
2023-3-2
编辑:the cyclist
2023-3-2
Here are two methods of finding the last index that is not NaN:
load("C.mat","c")
% Method 1
lastNonNanIndex1 = sum(not(isnan(c)))
% Method 2
lastNonNanIndex2 = find(not(isnan(c)),1,"last")
But if you don't need the index, and just want to trim it, then
c(isnan(c)) = []; % Trims the NaN values from the vector
numel(c) % Show the length of the new vector
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 EEG/MEG/ECoG 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!