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!