Filter löschen
Filter löschen

contour Plot Problems - Multiple wrong lines created

2 Ansichten (letzte 30 Tage)
Alberto Rinaldi
Alberto Rinaldi am 23 Mär. 2017
Beantwortet: Eeshan Mitra am 29 Mär. 2017
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')

Antworten (1)

Eeshan Mitra
Eeshan Mitra am 29 Mär. 2017
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')

Kategorien

Mehr zu Contour Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by