I have a several datasets which are Nx2 size. Say, it is called dat1. I want to make a wrapper function myplot() to plot it using plot() function without doing plot(dat1(:,1), dat1(:,2)) every time.
It is not a problem, but I want to be able to use all the other properties like 'LineWidth', marker etc. the same way as plot().
How do I make a wrapper myPlot() that can interpret the variable arguments similar to plot()? It should look like this:
myPlot(dat1, 'rx') should translate to plot(dat1(:,1), data1(:,2),'rx')
myPlot(data1, 'Linewidth',2) should translate to plot(dat1(:,1), data1(:,2),'Linewidth',2)
Edit: Thanks. Found an answer elsewhere
function h = myPlot(varargin)
dat = varargin{1};
h = plot(dat(:,1), dat(:,2), varargin{2:end});
How about
myPlot = @(data, varargin) plot(data(:,1), data(:,2), varargin{:})
This creates an anonymous function as per @MichaelTr7's answer, but makes it more flexible by accepting varargin, and then expanding that in the call to plot. (This is a standard technique for passing through extra arguments unchanged to another function).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With