function whose arguments contains a function with possibly a variable number of outputs

1 回表示 (過去 30 日間)
I am writing a class which calls matrix and vector matlab functions adding some stuff to obtain an approximation of the number of significant bits.
For example with A=hilb(10) whose condition number is about 1e13 if I compute det(A) A beeing an object of my class I obtain 2.1640e-53 the number of displayed digits is automatically limited to the expected correct ones. To achive this I overload matlab function as shown below:
%%%%
methods
function C=mldivide(A,B), C=rfpa.OP(@mldivide,A,B);end
function d=det(A), d=rfpa.OP(@det,A);end
function B=inv(A), B=rfpa.OP(@inv,A);end
function c=cond(A), c=rfpa.OP(@cond,A);end
......
%%%
OP is a static method :
function xr=OP(fun,varargin)
x1=fun(varargin{:});
xr=zeros(size(x1),'rfpa');
.....
This works fine but I have not found how to do, when function has a variable number of outputs as QR SVD for example.
Is it possible to implement something like
function varargout=OP(fun,varargin)
[varargout{1:nargout}]=fun(varargin{:});
.....
My current solution is to have specific wrapper for QR SVD etc... which is no intellectually satisfactory.
Any help will be welcome.
Alain

採用された回答

Steven Lord
Steven Lord 2021 年 8 月 31 日
See this documentation page, specifically the section on How to Use Comma-Separated Lists.
  1 件のコメント
Alain Barraud
Alain Barraud 2021 年 9 月 1 日
OK, According to the Function Return Values example it is necessary to add nargout as a input parameter within my function OP. Now it works as expected.
Thanks a lot
Alain

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by