⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bsxarg.m

📁 bsxfun, 一個matlab中十分常用的函數. 可以快速地對matrix進行接位複合運算~~
💻 M
字号:
% bsxarg does singleton expansion of two input arrays (related to bsxfun)%******************************************************************************% %  MATLAB (R) is a trademark of The Mathworks (R) Corporation% %  Function:    bsxarg%  Filename:    bsxarg.c%  Programmer:  James Tursa%  Version:     1.0%  Date:        February 09, 2008%  Copyright:   (c) 2008 by James Tursa, All Rights Reserved%  Permission:  Permission is granted to freely distribute and use this code%               as long as the header information is included.% %  Returns the singleton expanded arrays that are virtually used in bsxfun.%  Limited to a maximum of 12 dimensions.% %  bsxfun performs binary operations on input arrays, where singleton%  dimensions are virtually expanded to perform the operation. bsxarg will%  actually do the singleton expansion and return the expanded arrays.% %  Building:% %  >> mex -setup%    (then follow instructions to select a C / C++ compiler of your choice)%  >> mex bsxarg.c% %  Syntax% %  [C D] = bsxarg(A,B)% %  Description% %  C = the expanded version of A.%  D = the expanded version of B.% %  Each dimension of A and B must either be equal to each other, or equal to 1.%  Whenever a dimension of A or B is singleton (equal to 1), the array is %  virtually replicated along the dimension to match the other array. The array%  may be diminished if the corresponding dimension of the other array is 0.% %  The size of the output arrays C and D are equal to:% %  max(size(A),size(B)).*(size(A)>0 & size(B)>0).% %  Examples%  %   >> A = 10*rand(2,1,2)%   A(:,:,1) =%     9.3181%     4.6599%   A(:,:,2) =%     4.1865%     8.4622% %   >> B = 10*rand(1,3)%   B =%     5.2515    2.0265    6.7214% %   >> [C D] = bsxarg(A,B)%   C(:,:,1) =%    9.3181    9.3181    9.3181%    4.6599    4.6599    4.6599%   C(:,:,2) =%    4.1865    4.1865    4.1865%    8.4622    8.4622    8.4622% %   D(:,:,1) =%    5.2515    2.0265    6.7214%    5.2515    2.0265    6.7214%   D(:,:,2) =%    5.2515    2.0265    6.7214%    5.2515    2.0265    6.7214% %  User's with older versions of MATLAB that do not have the bsxfun intrinsic%  available to them can use this simple m-file to get that capability:% %   function C = bsxfun(fun,A,B)%   if( nargin ~= 3 )%       error('Need 3 arguments for bsxfun')%   end%   [AX BX] = bsxarg(A,B);%   if( ischar(fun) )%       C = eval([fun '(AX,BX)']);%   else%       C = fun(AX,BX);%   end%   return%   end% % *******************************************************************************/function [C D] = bsxarg(A,B)disp('Error using bsxarg: You have not yet generated the bsxarg mex routine.');disp('Do the following:');disp(' ');disp('>> mex -setup');disp('  (Then follow instructins to select the C compiler of your choice. (e.g., lcc)');disp('>> mex bsxarg.c');disp(' ');disp('That''s it! Now you are ready to use bsxarg.');error(' ');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -