Contour plot with 3 variables

4 Ansichten (letzte 30 Tage)
Collin Poesch
Collin Poesch am 11 Jun. 2018
Beantwortet: Anton Semechko am 11 Jun. 2018
I have x,y,z. All are a 1 by 30 matrix. I have an equation f(x,y,z). I want to plot f with its respective x and y values. I can get it to contour it but it just looks like a bunch of lines all over. How can I make it look more readable?
if true
% code
y= [129.9963226 129.8226166 129.9604645 103.7347794 103.6901093 103.6944962 110.161171 110.1717148 110.1349182 75.09435272 75.70821381 75.47728729 157.7270355 157.7238922 157.7770691 140.2634125 140.3300629 140.2582855 96.6153183 97.34350586 97.02552795 72.46351624 72.47560883 72.20365143 103.9134598 104.9690857 104.4163437 138.0762329 138.0917053 138.0798492];
x= [41.68254852 41.70171356 41.67147064 36.74276733 36.78116226 36.65636063 18.88254356 18.78098297 18.82348824 39.41556168 39.41479111 39.41047287 43.82479095 43.82077408 43.85306549 58.31668854 58.42596817 58.48091125 58.46498489 58.4274826 58.50025558 2.808314323 2.768934727 2.80451417 2.700401783 2.800596714 2.729904413 2.733380079 2.710067749 2.785956144];
z=[54.63507843 70.93000793 61.16201401 49.93524933 62.1734848 55.09511566 31.75339317 55.34885788 41.20726013 51.8176651 55.26327896 53.50642776 58.3914032 72.26363373 64.19233704 72.59120941 77.98557281 75.36292267 71.80627441 75.89244843 73.77413177 14.37912369 32.71578979 22.74474907 15.13825035 55.60447693 31.62221718 16.6245079 60.80334091 35.1770134];
[x,y]=meshgrid(x,y);
f=-6 -1.69*x +.78*y+.739*z -.0165*x.^2-.0106*y.^2+.0188*x.*y+.000097*x.^3+.000039*y.^3-.000151*x.^2.*y -.000105*x.*y.^2+.000203*x.*y.*z
contour(x,y,f)
if true
% code
end

Antworten (1)

Anton Semechko
Anton Semechko am 11 Jun. 2018
% Grid
y=70:160;
x=0:60;
z=10:80;
[X,Y,Z]=meshgrid(x,y,z);
% Evaluate function at grid points
F=-1.69*X +.78*Y + .739*Z - .0165*X.^2 - .0106*Y.^2 + .0188*X.*Y + ...
.000097*X.^3 + .000039*Y.^3 - .000151*X.^2.*Y - .000105*X.*Y.^2 + .000203*X.*Y.*Z - 6;
% Iso-values of F
n=30; % number of evenly spaced isocontours to visualize
F_min=min(F(:));
F_max=max(F(:));
df=(F_max-F_min)/(n+2);
v=round((1:n)*df);
% Visulize xy-slices at z= 10, 30, 50, and 70
figure('color','w')
zi=[10 30 50 70];
id=[1 21 41 61]; % xy slice indices
for i=1:numel(id)
ha=subplot(1,4,i);
axis equal on
hold on
imagesc([x(1) x(end)],[y(1) y(end)],F(:,:,id(i)));
set(ha,'Xlim',[x(1) x(end)],'Ylim',[y(1) y(end)],'box','on','CLim',[F_min F_max])
[~,h]=contour(X(:,:,id(i)),Y(:,:,id(i)),F(:,:,id(i)),v,'LevelListMode','manual','ShowText','on');
set(h,'LineColor','k','LineWidth',1)
uistack(h,'top')
set(get(ha,'Title'),'String',sprintf('z = %.1f',zi(i)),'FontSize',15)
end

Kategorien

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

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by