Code Monkey home page Code Monkey logo

Comments (1)

lnadolski avatar lnadolski commented on July 20, 2024

For Matlab 2009

For an empty cell array, Matlab 2009 does return an empty cell array but a single empty cell. (use in AT/linopt)

%% 2009/2016
For Matlab 2016
MS = Empty array: 4-by-4-by-0
K>> num2cell(MS,[1 2])
Empty cell array: 1-by-1-by-0

En Matlab 2009
MS = Empty array: 4-by-4-by-0
K>> num2cell(MS,[1 2])
{}

%% Example to run if One wants to make an autotest
M = int16.empty(4,4,0)
M = Empty array: 4-by-4-by-0
B = num2cell(M, [1 2])
B = Empty cell array: 1-by-1-by-0

% SOLUTION for 2009
A quick fix : replace cell2num by commenting the following lines
% if isempty(a)
% c = {};
% return
% end

fullfile is given below:

function c = num2cell(a,dims)
%NUM2CELL Convert numeric array into cell array.
% C = NUM2CELL(A) converts numeric array A into cell array C by placing
% each element of A into a separate cell in C. The output array has the
% same size and dimensions as the input array. Each cell in C contains
% the same numeric value as its respective element in A.
%
% C = NUM2CELL(A, DIM) converts numeric array A into a cell array of
% numeric vectors, the dimensions of which depend on the value of the DIM
% argument. Return value C contains NUMEL(A)/SIZE(A,DIM) vectors, each of
% length SIZE(A, DIM). The DIM input must be an integer with a value from
% NDIMS(A) to 1.
%
% C = NUM2CELL(A, [DIM1, DIM2, ...]) converts numeric array A into a cell
% array of numeric arrays, the dimensions of which depend on the values
% of arguments [DIM1, DIM2, ...]. Given the variables X and Y, where
% X=SIZE(A,DIM1) and Y=SIZE(A,DIM2), return value C contains
% NUMEL(A)/PROD(X,Y,...) arrays, each of size X-by-Y-by-.... All DIMn
% inputs must be an integer with a value from NDIMS(A) to 1.
%
% NUM2CELL works for all array types.
%
% Use CELL2MAT or CAT(DIM,C{:}) to convert back.
%
% See also MAT2CELL, CELL2MAT

% Clay M. Thompson 3-15-94
% Copyright 1984-2008 The MathWorks, Inc.
% $Revision: 1.18.4.5 $ $Date: 2008/12/29 02:10:31 $

error(nargchk(1,2,nargin,'struct'));

% if isempty(a)
% c = {};
% return
% end
if nargin==1
c = cell(size(a));
for i=1:numel(a)
c{i} = a(i);
end
return
end

% Size of input array
siz = [size(a),ones(1,max(dims)-ndims(a))];

% Create remaining dimensions vector
rdims = 1:max(ndims(a),max(dims));
rdims(dims) = []; % Remaining dims

% Size of extracted subarray
bsize = siz;
bsize(rdims) = 1; % Set remaining dimensions to 1

% Size of output cell
csize = siz;
csize(dims) = 1; % Set selected dimensions to 1
c = cell(csize);

% Permute A so that requested dims are the first few dimensions
a = permute(a,[dims rdims]);

% Make offset and index into a
offset = prod(bsize);
ndx = 1:prod(bsize);
for i=0:prod(csize)-1,
c{i+1} = reshape(a(ndx+i*offset),bsize);
end

from at.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.