Hello,
I wanted to use the myttest.m function in the brainstorm/toolbox directory, but in some cases, it calls the function “subarray” (l.42-43) which doesn’t exist on my installation, neither in the brainstorm toolbox nor in the matlab + signal processing toolbox package.
Is it normal (function myttest no longer in use…)?
Thanks,
-Vincent
Indeed, the subarray function is missing.
Thanks for pointing this out Vincent. I’ll post this function in this thread and include it in the distribution package as soon as I’m back at my desk (by tomorrow afternoon).
Cheers,
It’s all me: I had forgotten to include this function. It is now part of the package (in Toolbox directory, at revision 180).
I also put the function code below for those who need it now (please, include it as subarray.m in the Toolbox directory).
have fun,
function [y]=subarray(X,varargin)
% subarray - retrieve values from a ND-array
%
% [y]=subarray(X,idx,dim)
% [y]=subarray(X,idx1,dim1,idx2,dim2,...)
% [y]=subarray(X,{idx1,dim1,idx2,dim2,...}) or {idx{:};dim{:}}
% Retrieves a sub part of a N-dimension array
%
% INPUTS:
% X: a N-dimension array
% idx: indices of values to retrieve in the given dimension
% idx shouold be a list of integer.
% If idx is zero or negative, count starts from the end
% subarray(X,-2,2) outputs X(:,end-2,...)
% subarray(X,0,1) outputs X(end,...)
% dim: dimension on which the operation is done
% if dim<0: remove the subpart and ouput the remainder
% (default: first non-singleton)
%
% This function is useful when one doesn't know the number of
% dimensions of X. E.g. to retrieve the 3rd and 4th "line" of the 2nd
% dimension of a ND array (say, X is N-by-5-by-P-by...)
% >> subarray(X,[3 4] ,2)
% ouputs a N-by-[2]-by-P-by.... array
%
% NB: if X is a vector, subarray(X,n) outputs the n-th value
% Author: K. N'Diaye, kndiaye01<at>yahoo.fr
% Copyright (C) 2005
% This program is free software; you can redistribute it and/or modify it
% under the terms of the GNU General Public License as published by the
% Free Software Foundation; either version 2 of the License, or (at your
% option) any later version: http://www.gnu.org/copyleft/gpl.html
%
% ----------------------------- Script History ---------------------------------
% KND 2005-05-01 Creation
% KND 2006-06-10 Added negative idx starting from the end
% ----------------------------- Script History ---------------------------------
sx=size(X);
dim=[];
if nargin<2
error('No indices given!')
elseif nargin>2
inputs=varargin;
if rem(nargin-1,2)
error('Indices & dimensions should be given in pairs')
end
else
if iscell(varargin{1})
inputs=varargin{1}(:)';
ninputs=length(inputs);
else
inputs=varargin(1);
dim=[find(sx>1) 1];
inputs{2}=dim(1);
end
end
idx=inputs(1:2:end);
dim=[inputs{2:2:end}];
exclude=logical(dim<0);
dim=dim.*(1-2*exclude);
if any(dim==0)
error('Dimension can''t be zero!')
end
% Check for any negative indices, which should then be
% counted from the end
for i=1:length(idx)
idx{i}(idx{i}<=0)=sx(dim(i))+idx{i}(idx{i}<=0);
end
nd=ndims(X);
% find unspecified dims
unspec=setdiff(1:nd, dim);
S.type='()';
S.subs=cell(nd,1);
S.subs(dim(~exclude))=idx(~exclude);
S.subs(unspec)=repmat({':'}, size(unspec));
for i=1:find(exclude)
S.subs{dim(i)}=setdiff(1:sx(dim(i)),idx{i});
end
y=subsref(X,S);
return
Karim,
You’re the fastest greatest !
thanks -
to all: as usual the entire package will be updated in the dowbload section nightly.