To plot contour for an array : x,y,mass value having repeated values

조회 수: 6 (최근 30일)
sanjeet
sanjeet 2015년 8월 20일
댓글: sanjeet 2015년 8월 22일
I m trying to plot a contour for a array (x,y,mass2): it is huge in size . The code is :
% initialise square matrix for contour of mass
mass2=zeros(length(xyz),length(xyz));
for i=1:length(xyz)
mass2(k,k)=xyz(i);
end
m2=max((diag(mass2*1e6)));
m1=min(mean(diag(mass2*1e6)));
contourlevel = m1:((m2-m1)/3):m2; % Required contour for 10 scale to 100
contour(xyz(1,:),xyz(2,:),(log10((mass2*1e6))),contourlevel);
My code shows the following error:
Error using contour (line 55)
Vector X must be strictly increasing or strictly decreasing with no repeated values.
Error in mass_2Dplane_z (line 151)
contour(y1,z1,(log10((mass2*1e6))),contourlevel)
My proble: high time in creating the square matrix for mass, and the isue of x array no being increasing order and the repeated values

채택된 답변

Kelly Kearney
Kelly Kearney 2015년 8월 20일
편집: Kelly Kearney 2015년 8월 20일
Is xyz a set of scattered 2D points and their corresponding z-data? If so, the crazy diagonal matrix you're building is not what you want. You have two choices to create your contour:
1) Download one of these functions, designed to contour scattered data.
tri = delaunay(xyz(:,1), xyz(:,2));
tricontour(tri, xyz(:,1), xyz(:,2), xyz(:,3), clev);
2) Interpolate the data onto a regular grid.
xg = linspace(min(xyz(:,1)), max(xyz(:,1)), 50);
yg = linspace(min(xyz(:,2)), max(xyz(:,2)), 50);
[xg,yg] = meshgrid(xg,yg);
F = scatteredInterpolant(xyz(:,1), xyz(:,2), xyz(:,3));
zg = F(xg,yg);
contour(xg,yg,zg, clev);
I prefer the former option, usually.
  댓글 수: 1
sanjeet
sanjeet 2015년 8월 22일
Thanks I got the contour: Can you advise if i need the filled contour in place of lines... I tried gridfit but there is some issue with the output being different from the actual result

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

추가 답변 (0개)

카테고리

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