I'm trying to make a contour map but I keep running into a small issue. Does anyone know what I have to do to either my function file or script file?

1 view (last 30 days)
function [V] =TPF(P,r,z)
%UNTITLED6 Summary of this function goes here
j=length(r);
n=length(z);
VS=zeros(j,n);
for i=1:j
for k=1:n
VS(i,k)=((3*P)./(2*pi*z(k).^2)).*1./((r(i)./z(k)).^2+1).^(5/2);
end
end
end
----------------------------------------------------------------
clear all
close all
r=(-1:0.1:1);
z=(0.5:0.1:2);
P=1000;
[R,Z]=meshgrid(r,z);
[V]=TPF(P,R,Z);
figure(1)
cs=contour(R,Z,V);
clabel(cs);
figure(2)
cs=contourf(r,z,V);
colorbar
figure(3)
surfc(r,z,V)

Answers (2)

Walter Roberson
Walter Roberson on 29 Jul 2015
Use ndgrid() instead of meshgrid()

Cedric
Cedric on 29 Jul 2015
Edited: Cedric on 29 Jul 2015
Your function doesn't define it's output argument V, but another variable VS.
You should change the double FOR loop for a vector approach if you can.
PS: it seems that you can replace the whole function call with
V = 3*P./(2*pi*Z.^2) .* 1./((R./Z).^2+1).^(5/2) ;
which is the vector approach mentioned above. Just check that it works.

Categories

Find more on Contour Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!