I cannot give this struct as input of a custom function, how can I do?
조회 수: 2 (최근 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!