Customize dbstop in MATLAB

If you use the editor, you can set a stop as normal, right-click on it, select “set/modify condition” and enter the condition (the stop will turn from red to yellow). From command line, you can use dbstop in file if expression dbstop in file at location if expression e.g. dbstop in myFile at 200 if … Read more

globals and parfor

From the documentation on parfor: The body of a parfor-loop cannot contain global or persistent variable declarations. In the context of your problem, i.e., calling a function within the parfor that in turn references a global, this translates into: “parfor will probably not give expected or meaningful results”. This makes perfect sense. Consider the following … Read more

How to perform interpolation on a 2D array in MATLAB

Here is an example using scatteredInterpolant: %# get some 2D matrix, and plot as surface A = peaks(15); subplot(121), surf(A) %# create interpolant [X,Y] = meshgrid(1:size(A,2), 1:size(A,1)); F = scatteredInterpolant(X(:), Y(:), A(:), ‘linear’); %# interpolate over a finer grid [U,V] = meshgrid(linspace(1,size(A,2),50), linspace(1,size(A,1),50)); subplot(122), surf(U,V, F(U,V)) Note that you can evaluate the interpolant object at … Read more