pass input arguments of built in function as cell array or structure?
20 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Keith Regner
am 20 Mär. 2023
Kommentiert: VBBV
am 21 Mär. 2023
For example, I want to call the plot command but only provide one input to the function where X and Y are stored in that input. Something like:
S.X = 1:10;
S.Y = cos(X);
plot(S)
or, can I save X and Y in cell array like:
S{1,1} = 'X';
S{2,1} = 1:10;
S{1,2} = 'Y';
S{2,2} = cos(X);
plot(S{:})
Ultimately, I'd like to call feval and provide all the inputs required for the function to be saved in one variable
feval('plot',S)
thank you
1 Kommentar
VBBV
am 21 Mär. 2023
plot function does not allow direct use of struct to graph the data.
S.X = 1:10;
S.Y = cos(S.X);
plot(S.X,S.Y)
Akzeptierte Antwort
Walter Roberson
am 21 Mär. 2023
feval('plot', S{:})
feval does not support passing in any kind of structured input .
Most functions do not support providing some kind of structured input that describes the parameters and options to the function. Some functions do support that -- for example some of the optimization functions support that
Although if you use arguments blocks then the processing of name/value pairs looks like structure access, that does not mean that you can pass a structure and the structure will be treated as describing name/value pairs. If your function wants to support a struct of parameters, then it must do so explicitly.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
