Variables corresponding with NaN won't graph

조회 수: 13 (최근 30일)
William
William 2023년 6월 2일
댓글: William 2023년 6월 2일
So in my code there are two variables being gathered from a plot. b1 does not include the NaN because of the code setting all NaN to zero and then excluding all zero values. But the coresponding value in b2 is still there meaning that it wont graph because there are not an equal amount of values in each list. What is the best way to get around this and exclude the value in b2 as well?

채택된 답변

Cris LaPierre
Cris LaPierre 2023년 6월 2일
Use an index to tell plot which values to plot.
ind = ~ismissing(b1);
plot(b1(ind),b2(ind))
  댓글 수: 1
William
William 2023년 6월 2일
Worked! Thank you very much for a quick reply

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

the cyclist
the cyclist 2023년 6월 2일
편집: the cyclist 2023년 6월 2일
Without seeing your code or your data, it is difficult to give specific advice. But the gist would be something like this:
  • identify the NaN values in b1, e.g. nanb1 = isnan(b1)
  • remove the values from b2 that correspond to those NaN values, e.g. b2(nanb1) = []

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by