[Scilab-users] overloading concat "[ ]" operators
philippe
rouxph.22 at gmail.com
Sun Jul 3 22:40:04 CEST 2016
Le 01/07/2016 11:33, Samuel Gougeon a écrit :
> Hello Philippe,
> You shall use a mlist() instead of a tlist.
> Have a look at https://help.scilab.org/docs/6.0.0/en_US/mlist.html
> mlist are array-oriented.
thanks Samuel, I will create mbigint as a mlist containing the cell of
bigint and a string matrix of the same size (I already have a bigint2str
function) :
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x=bigint(123456789);
y=bigint(987654321);
z=x-y;
T=cell()
T(1,1).entries=x;
T(1,2).entries=y;
T(2,1).entries=z;
T(2,2).entries=bigint(0);
M=mlist(['mbigint','display','value'],..
[bigint2str(x) bigint2str(y); bigint2str(z) '0' ],T)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The display for mbigint is just M.display
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function %mbigint_p(M)
disp(M.display)
endfunction
-->M
M =
!123456789 987654321 !
! !
!-864197532 0 !
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
the extraction for mbigint is exactly as in the help page :
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function r=%mbigint_e(varargin)
M=varargin($)
r=mlist(['mbigint','display','value'],..
M.display(varargin(1:$-1)),M.value(varargin(1:$-1)))
endfunction
-->M(2,:)
ans =
!-864197532 0 !
-->M(:,1)
ans =
!123456789 !
! !
!-864197532 !
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
as well as insertion :
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function M=%mbigint_i_mbigint(varargin)
M=varargin($)
N=varargin($-1)
M.value(varargin(1:$-2))=N.value
M.display(varargin(1:$-2))=N.display
endfunction
-->M(1,1)=M(2,2)
M =
!0 987654321 !
! !
!-864197532 0 !
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
it remains to write %mbigint_c_mbigint and %mbigint_f_mbigint
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function M=%mbigint_c_mbigint(A,B)
M=mlist(['mbigint','display','value'],..
[A.display B.display],..
[A.value B.value])
endfunction
function M=%mbigint_f_mbigint(A,B)
M=mlist(['mbigint','display','value'],..
[A.display;B.display],..
[A.value;B.value])
endfunction
--> [M M]
ans =
!0 987654321 0 987654321 !
! !
!-864197532 0 -864197532 0 !
--> [M;M]
ans =
!0 987654321 !
! !
!-864197532 0 !
! !
!0 987654321 !
! !
!-864197532 0 !
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Finally Samuel have you any idea for my previous question abou how to
replace unix('sed ...') by a "scilab-only" command ;-)
Philippe
More information about the users
mailing list