I have 20-40 discrete figures to create and save in a Matlab program. I am trying to create a function which will allow me to input elements (images, lines, vectors etc) and create layered plots by passing each element to plot() in a for loop:
function [ ] = constructFigs( figTitle, backgroundClass, varargin )
fig = figure('visible', 'off');
if strcmp(backgroundClass, 'plot') == 1
plot(varargin{1});
elseif strcmp(backgroundClass, 'image') == 1
imshow(varargin{1});
end
for i = 1:length(varargin)
hold on
if ndims(varargin{i}) == 2
plot(varargin{i}(:, 1), varargin{i}(:, 2))
else
plot(varargin{i});
end
end
saveas(fig, figTitle);
close(fig);
end
This function works but is very limiting in terms of what can be plotted; you cannot perform certain types of plotting operations (superimposed images for example) and cannot pass in optional arguments to plot(). What I would like to do is pass in a structure of elements to be plotted and then pass these structure elements into plot() as arguments. For example (simplified and with bad syntax):
toBePlotted = struct('arg1', {image}, 'arg2', {vector1, vector2, 'o'})
plot(toBePlotted.arg1)
plot(toBePlotted.arg2)
I am able to programmatically construct the structures with argument names, but I am unable to extract the elements from the structure in a way that plot will accept them as arguments.
Any help would be greatly appreciated