Extract all numbers from a matrix that also contains NaN into a single vector

조회 수: 7 (최근 30일)
Hi there I have a large matrix that contains numbers (both positive and negative) and NaN. I need to find the median of this matirx to plot a line.
Doing the median on the whole matrix gives me a value followed by NaNs which I cannot plot as a line.
I have tried the following:
realidx = arrayfun(@isreal,a);
only_reals = a(realidx);
only_real_part = real(a);
but it just gives me lots of 1s. I need the actual values extracting.. I also need all the values to be in one vector other wise all the columns would be of diferent lengths.
Any help would be amazing!
Thanks

채택된 답변

Stephan
Stephan 2019년 3월 12일
편집: Stephan 2019년 3월 12일
A = [1 2 3; NaN -2 0; NaN 5 -8]
result = A(~isnan(A))
gives.
A =
1 2 3
NaN -2 0
NaN 5 -8
result =
1
2
-2
5
3
0
-8
Best regards
Stephan

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by