Borrar filtros
Borrar filtros

How To Generate Field Names from Variables

2 visualizaciones (últimos 30 días)
Krzysztof
Krzysztof el 21 de Nov. de 2013
The following code behaves rather unexpectedly to me:
r .ab = 'cd';
try assert (r .([ 'a'; 'b' ]))
catch e
assert (all (e .identifier == 'MATLAB:nonExistentField'))
end
assert (all (r .([ 'ax'; 'bx' ]) == 'cd'));
It seems that MATLAB considers only (fieldname (:, 1)), except when there is only one column, in which case it considers only (fieldname (1)). All this is undocumented. Isn’t that weird? I would expect MATLAB to error out with 'mustBeFieldName' in both cases instead.

Respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by