Structure variable as input in MATLAB function using VARARGIN
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Luigi
el 17 de Sept. de 2018
Respondida: KSSV
el 17 de Sept. de 2018
I wrote a main function in Matlab that calls other functions, each of which produces plots in a new figure. Though each function produces different plots (different colors, number of subplots, and so on) they all share some features (font, fontsize, Linewidth etc.). In order to make it easier to modify the aforementioned shared parameter for all the MATLAB figures, I have defined in the preamble of the main function a structure variable as follows:
var.font = 'Arial Unicode MS';
var.fontsize = 13;
var.interpreter = 'none' ;
and so on for the other fields. When I call the function in this way (providing the structure as input):
function plot1( var , ... )
fig = gcf
fig.Position(3) = var.Position3
fig.Position(4) = var.Position4
end
everything works fine and the functions apply the feature to each figure. But if I try to provide a variable number of input to the functions using varargin, in this way
function plot1( varargin )
fig = gcf;
temp = varargin(1);
fig.Position(3) = temp.Position3;
fig.Position(4) = temp.Position4;
end
The following error message is prompted "Struct contents reference from a non-struct array object."
0 comentarios
Respuesta aceptada
KSSV
el 17 de Sept. de 2018
function plot1( varargin )
var = varargin{1} ;
fig = gcf;
temp = var(1);
fig.Position(3) = temp.Position3;
fig.Position(4) = temp.Position4;
end
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!