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 CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by