Using matlabsub in spreadsheet toolbox
조회 수: 1 (최근 30일)
이전 댓글 표시
How do you use matlabsub with matlab functions that return more than one thing? For instance, I am using it with princomp to do a principal component anaylsis, and am really interested in the variances returned, which are the third thing returned. I can only get it to display the coefficients, which are the first thing returned.
댓글 수: 0
답변 (1개)
Walter Roberson
2011년 8월 18일
You don't. matlabFunction works on symbolic functions, not on MATLAB functions; you cannot call princomp from inside a pure symbolic formula (because it is not a MuPad routine) and you probably cannot pass princomp symbolic parameters.
MuPad (and Maple ) symbolic functions only ever return one value, but that one value might be an "expression sequence". If there are multiple left-hand-side variables on a MuPad ":=" assignment then the elements of the expression sequence get assigned to the corresponding output variable. If there is only one output variable, it gets assigned the entire expression sequence; if there is otherwise a mismatch between the number of output variables on the assigment and the number of elements in the expression sequence, there there will be an error generated.
A common trick to working with a MuPad function that returns an expression sequence is to include the entire expression inside of the list-building operators [] . For example, within MuPad,
f := () -> 18, 7, 23;
means that f is a function that takes no arguments and returns an expression sequence with 3 elements. You can get the list form of this via, e.g., R := [f()] which would return the list [18, 7, 23] and assign that to the variable R. You could then refer to the second output of f by referring to R[2]
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MuPAD에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!