Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

atlinopt error in matlab 2009 #48

Closed
ZeusMarti opened this issue Mar 26, 2018 · 1 comment
Closed

atlinopt error in matlab 2009 #48

ZeusMarti opened this issue Mar 26, 2018 · 1 comment

Comments

@ZeusMarti
Copy link
Contributor

Hi,

In matlab 2009 (I checked that Matlab2017 version works fine), I get the following error message:

[LinData,~, ~] = atlinopt(THERING,0,1);

_??? Error using ==> struct
Array dimensions of input 10 must match those of input 2 or be scalar.
Error in ==> atlinopt at 124
ld = struct('ElemIndex',num2cell(find(REFPTS)),...
Error in ==> atlinopt at 119
[LD, tunesP] = atlinopt(RING,DP+0.5*dDP,refs,o1P); %#ok

This line appears in atsummary, so it makes atsummay not to work, however, the command atlinopt(THERING,0,1) works whithout problem. I guess an empty cell array and {} are not the same thing in Matlab2009, but I'm not sure...

Someone has any idea how to make it compatible with both versions?

Cheers,

Zeus

@lnadolski
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants