Created
November 19, 2013 08:22
-
-
Save nh2/7542053 to your computer and use it in GitHub Desktop.
Simple way to plot a function taking 2 arguments in Matlab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Simple way to plot a function taking 2 arguments. | |
% Usage: | |
% plot3d( @(x,y) x^2+y^2, range1, range2 ) | |
function plot3d(f, range1, range2) | |
% mesh really wants it in this order :( | |
r = zeros(length(range2), length(range1)); | |
[X, Y] = meshgrid(range1, range2); | |
s1 = size(range1) | |
s2 = size(range2) | |
sx = size(X) | |
sy = size(Y) | |
for ix = 1:length(range1) | |
for iy = 1:length(range2) | |
% mesh really wants it in this order :( | |
r(iy, ix) = f( X(iy, ix), Y(iy, ix) ); | |
end | |
end | |
mesh(X, Y, r); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment