Use .mat file as input argument in a function.
조회 수: 14 (최근 30일)
이전 댓글 표시
Assuming a Data.mat file has a table of rows and columns, how can it be used as input arguement so that the elements in any row/column be called up for use in the function?
댓글 수: 0
답변 (1개)
Siddharth Bhutiya
2022년 4월 5일
If you look at the value of K in your screenshot you will notice that it is a struct and one of the fields would be the table you are looking for (the name would be the name that you used while creating the MAT file). Once you figure out the name you can use the dot syntax to pass that as input to another function.
>> K = load("data.mat")
K =
struct with fields:
myTable: [4×4 table]
>> SVdata(K.myTable)
댓글 수: 11
Stephen23
2022년 4월 7일
편집: Stephen23
2022년 4월 7일
"However, i am having unrecognized function error whenever i tied to call the function from command window. "
Because you have written a script, not a function file.
As I already explained in this comment, you cannot write a script and also call the local function from the command line. That simply will not work. Just as I wrote before, you need to decide:
- if you want to be able to call the function from the command line then you need to get rid of all code that is not within function...end . See: https://www.mathworks.com/help/matlab/ref/function.html
- if you really want a script (as you have now), then you cannot call the local function from the command line. See: https://www.mathworks.com/help/matlab/matlab_prog/local-functions-in-scripts.html
You have to decide what you want to do.
참고 항목
카테고리
Help Center 및 File Exchange에서 Reference Applications에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!