Wrapper function in Matlab for plotting multidimensional functions in 3D

I have often encountered situation where I want to plot a function in 3D but it either takes multidimensional input or the function itself can't be specified over some kind of matrix multiplication. So I wrote this the other night, a wrapper function for the 3D plotting in Matlab. Basically it takes a function handle and the domain of the two variables it is supposed to vary and outputs a 3D mesh plot. I also implemented a parfor loop in it so if one wants additional speedup just start Matlabpool.

Download plotMyFunIn3D

See file attachment for download and here is the function head

% function  plotMyFunIn3D ( fun, input, domain, variable_dims, varargin )
%
% usage
%     plotMyFunIn3D ( fun, domain, variable_dims )
%
% input
%     fun: Function handle of the function you want to plot.
%     input: A vector the same size as the input for the function with
%     the values to be held constant in it. The variable parts of the
%     vector can be put to zero or other.
%     domain: Domain of the variable input variables. It is written as a 4X4 
%                   matrix where each row specifies lower and upper bound.
%     variable_dims: Specifies the which input of the function i.e. dimension 
%     to be varied.
%     varargin: 1x2 vector. How fine the Mesh should be, by specifying how fine the
%     grid should be.
% 
% output
%     A 3D meshplot of the function on the specfied domain. 
%
% description
%     Takes a function using multiple dim vector input and does a 3D plot of it by
%     varying two chosen variables on the specified domain while keeping 
%     the other variables constant.
%
% copyright
%     CC BY-NC 3.0
%
% author
%     Martin Hjelm, mhjelm@kth.se

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>