I cannot give this struct as input of a custom function, how can I do?
3 次查看(过去 30 天)
显示 更早的评论
Good evening to all,
I was wondering if it is possible to give this structure as input of a custom function:
"hold_on" : 1
"box_on" : 1
"grid_on" : 0
"grid_minor" : 0
because I always get this error: Undefined function 'myfunction' for input arguments of type 'struct'
Can someone help me?
Thank you in advance!
0 个评论
回答(2 个)
Torsten
2023-1-12
编辑:Torsten
2023-1-12
Works without problems.
Have you saved an m-file named "myfunction.m" in your working directory ?
var.hold_on = 1;
var.box_on = 1;
var.grid_on = 0;
var.grid_minor = 0;
class(var)
myfunction(var)
function [] = myfunction(var)
hold_on = var.hold_on
box_on = var.box_on
grid_on = var.grid_on
grid_minor = var.grid_minor
end
0 个评论
Steven Lord
2023-1-12
It is possible to write a function that accepts a struct array as input. Without seeing the body of your myfunction function we can't be certain of the cause of the error message you received, but if I had to guess I'd guess that your myfunction function was not defined as the first function in a file named myfunction.m.
If the file name and the function name differ, you will need to use the file name to call the function. So if "function myfunction(x)" was in a file named pizza.m you would have to call it by the name pizza.
Only the first function in a function file is directly callable by users outside that file.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!