How to compact an array with repeated data and NaNs?
이전 댓글 표시
Hi!
I have two vectors with measurement set points and an array with measurement values. The vectors and array contain repeated values and the array also contains NaNs. I would like to remove the repeated data and for the measurement set points where there are both a NaN and a value, I would like the value to remain.
For example, if the two vectors are called x and y and the array is called z.
x = [0 0.5 0.5 1 2]
y = [0 1 2 2 ]
z = [1 NaN 2 5 10; 7 3 3 NaN 2; 8 4 4 NaN NaN; 8 NaN 4 8 NaN]
I would like this to become
x = [0 0.5 1 2]
y = [0 1 2]
z = [1 2 5 10; 7 3 NaN 2; 8 4 8 NaN]
How do I do this in an easy way (I have quite a large array with data…)?
Thanks!
댓글 수: 3
James Tursa
2015년 3월 25일
편집: James Tursa
2015년 3월 25일
So you want the unique values of x and y to remain, and then delete the corresponding column(s) and row(s) of z based on what got deleted from x and y, but do so in a way that replaces any NaN's with values if there was a non-NaN available for that spot?
Can we assume that x and y are sorted as in your example?
Konstantinos Sofos
2015년 3월 25일
편집: Konstantinos Sofos
2015년 3월 25일
And what will happen in the case that all the values of a row are NaN or the dimensions are not consistent? In your example with Z matrix the output of the last row has 2 times the 8....
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 NaNs에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!