How do we plot a graph with non available values for y without breaking the continuity?
이전 댓글 표시
INTRO: I have an array M as below:
M=
1 4
2 NaN
3 10
4 NaN
5 NaN
6 15
7 NaN
8 17
9 59
10 NaN
GOAL: I want to plot the second versus the first column as follow:
M=load('M.txt');
h=plot(M(:,1),M(:,2));
PROBLEM: Due to the NaN, it does not plot the gaps correctly and breaks the continuity of the graph.
I wonder if someone could suggest me to some command lines that could fix this issue.
I thank you in advance for your help
Emerson
채택된 답변
추가 답변 (1개)
Azzi Abdelmalek
2012년 10월 25일
편집: Azzi Abdelmalek
2012년 10월 25일
Use interpolation
x=M(:,1);
y=M(:,2);
idx=find(~isnan(y))
y=interp1(x(idx),y(idx),x,'linear')
or remove rows containing nan
x=M(:,1);
y=M(:,2);
x(find(isnan(y)))=[]
y(find(isnan(y)))=[]
댓글 수: 2
Matt Tearle
2012년 10월 25일
idx = ~isnan(y);
No need for the find. (Sorry, I love logical indexing!)
Azzi Abdelmalek
2012년 10월 25일
I agree
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!