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?
Mostra commenti meno recenti
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)
1 Commento
DanTheMan
il 28 Lug 2015
Risposte (2)
Walter Roberson
il 29 Lug 2015
0 voti
Use ndgrid() instead of meshgrid()
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.
Categorie
Scopri di più su Contour Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!