[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #33216] cell2struct does not allow to create a
From: |
anonymous |
Subject: |
[Octave-bug-tracker] [bug #33216] cell2struct does not allow to create an empty struct |
Date: |
Tue, 03 May 2011 13:43:25 +0000 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1 |
URL:
<http://savannah.gnu.org/bugs/?33216>
Summary: cell2struct does not allow to create an empty struct
Project: GNU Octave
Submitted by: None
Submitted on: Tue 03 May 2011 01:43:24 PM UTC
Category: None
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: Improvement/Optimization
Status: None
Assigned to: None
Originator Name: Jochen Weber
Originator Email: address@hidden
Open/Closed: Open
Discussion Lock: Any
Release: 3.4.0
Operating System: Mac OS
_______________________________________________________
Details:
In many of my codefiles I'm currently using the following syntax to produce a
0x0 struct with a fix set of fields (against which I later run checks) but no
content (no memory required for pointers, etc.):
init_struct = cell2struct(cell(0, 0, 2), {'field1', 'field2'}, 3);
In Matlab this works as expected:
- taking the dims of the first input that are not the fieldnames dim (0 and
0) as output dims
- and then creating the output struct with the requested fields
As a workaround I'm currently using a function to initialize structs:
function s = emptystruct(fields, dim)
% argument check
if nargin < 1 || ...
~iscell(fields)
error( ...
'neuroelf:BadArgument', ...
'Bad or missing argument.' ...
);
end
if nargin < 2 || ...
~isa(dim, 'double') || ...
numel(dim) < 2 || ...
numel(dim) ~= size(dim, 2) || ...
any(isinf(dim) | isnan(dim) | dim < 0 | dim >= 2^31 | dim ~= fix(dim))
dim = [0, 0];
end
dim0 = (prod(dim) == 0);
% create struct
if numel(fields) == 0;
s = struct;
else
s = cell2struct(cell(numel(fields), 1), fields(:)', 1);
end
if dim0
s(:) = [];
if any(dim > 0)
s = reshape(s, dim);
end
else
s = repmat(s, dim);
end
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?33216>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
- [Octave-bug-tracker] [bug #33216] cell2struct does not allow to create an empty struct,
anonymous <=