필터 지우기
필터 지우기

contour Plot Problems - Multiple wrong lines created

조회 수: 2 (최근 30일)
Alberto Rinaldi
Alberto Rinaldi 2017년 3월 23일
답변: Eeshan Mitra 2017년 3월 29일
Hi everybody,
I have some problems with contour plot. The problem is very clear: running the following code, I do get additional lines to what I would like to expect (I get lines also for x=[4.33, 4.66, 6.33, 6.66]).
I would like to have the lines only for E>0;
Thanks in advance, Alberto
clc;
clear all;
close all;
E=[0 0.01 0.02 0.03 0 0 0.03 0.02 0.01 0;
0 0.01 0.02 0.03 0 0 0.03 0.02 0.01 0;
0 0.01 0.02 0.03 0 0 0.03 0.02 0.01 0;
0 0.01 0.02 0.03 0 0 0.03 0.02 0.01 0;
0 0.01 0.02 0.03 0 0 0.03 0.02 0.01 0;
0 0.01 0.02 0.03 0 0 0.03 0.02 0.01 0;
0 0.01 0.02 0.03 0 0 0.03 0.02 0.01 0;
0 0.01 0.02 0.03 0 0 0.03 0.02 0.01 0;
0 0.01 0.02 0.03 0 0 0.03 0.02 0.01 0;
0 0.01 0.02 0.03 0 0 0.03 0.02 0.01 0];
contour(1:size(E,1),1:size(E,2),E,0.01:0.01:max(E(:)),'linecolor','k')

답변 (1개)

Eeshan Mitra
Eeshan Mitra 2017년 3월 29일
The additional lines at x=[4.33, 4.66, 6.33, 6.66] represent those locations where the values of E are predicted to be 0.02, 0.01, 0.01, and 0.02, respectively. Please note that contour will interpret a continuous transition from 0.03 at x=4, to 0 at x=5, and not an instantaneous change.
As pointed out within the documentation link above, NaN values in the desirable ranges may be used to model discontinuities.
Note: You'll need to use the sizes of columns and rows for X and Y, respectively, within the contour command. The code presented above works only because the number of rows and columns are equal, which changes when NaN values are added. Instead, you should use:
contour(1:size(E,2),1:size(E,1),E,0.01:0.01:max(E(:)),'linecolor','k')

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by