How to plot contour plot with NaN in matrix ?

I have three matrices xvalues (X), yvalues (Y) and measured property (Z). All these three are upper triangular matrices with lower triangular part containing NaN values. How do I plot a contour plot only for the upper triangular part?

답변 (1개)

Star Strider
Star Strider 2014년 12월 10일
편집: Star Strider 2014년 12월 10일

0 개 추천

I would use the triu function. The lower triangular part would return as zeros.
If you plotted it as it currently exists, the NaN values would simply not plot anything, that is be blank areas of the contour plot.

댓글 수: 8

Karthik
Karthik 2014년 12월 10일
i want to plot only the upper triangular part. If i use zeros for lower triangular part, then the contour plot is getting affected by those zero values.
Star Strider
Star Strider 2014년 12월 10일
Then keep it as it is with the NaN values. The NaN values will not plot, leaving that part of the plot blank.
Karthik
Karthik 2014년 12월 12일
I am getting a contour plot. How can I plot a filled contour plot with the same matrices ?
Star Strider
Star Strider 2014년 12월 12일
Use the contourf function. It will provide filled contour plots.
Karthik
Karthik 2014년 12월 12일
I tried that but I don't see any plot. I see everything blank. Is there any way to manipulate the 'Z' matrix to plot a filled contour? Thanks
My pleasure.
I don’t have your data, so I’ve been simulating them with this code:
M = magic(10);
Mtu = triu(M);
Mtu(Mtu==0) = NaN;
figure(1)
contourf(Mtu)
This works. The other option you might consider is to increase the number of contour lines, for instance:
contourf(Mtu,50)
Karthik
Karthik 2014년 12월 12일
편집: Karthik 2014년 12월 12일
Hi, I attached the code. Actually, my Y matrix contains "Inf" on the main diagonal. To get rid of that value I replaced the lower part of X and Y matrices with NaN including the main diagonal. because, i am interested only in the upper part. When I use contour function, I am getting the desired plot. I need the same plot with filled contours. I tried the one suggested above. But, I also need the axes (X,Y) also shown. Thanks
I have no idea what you’re doing, but you can see what the result is if you replace the contourf plot with surfc:
surfc(X,Y,Z)
To see only ‘Z’:
surfc(Z)
The problems with ‘X’ and ‘Y’ can be seen if you plot them:
surfc(X)
surfc(Y)
The point is that ‘X’ and ‘Y’ are not linear, and ‘Z’ seems not to exist along the diagonal.
I’ll leave you to sort these. The plotting is trivial once you deal with whatever is going on with your data.

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

카테고리

도움말 센터File Exchange에서 Contour Plots에 대해 자세히 알아보기

질문:

2014년 12월 10일

댓글:

2014년 12월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by