Repmat converts '' to []

1 visualización (últimos 30 días)
Aditya Jain
Aditya Jain el 30 de Oct. de 2015
Comentada: Aditya Jain el 11 de Nov. de 2015
I want to create an array of structs
I am using the following code
structElement = struct('a', '', 'b', '', 'c', []);
ans = repmat(structElement, [4,1]);
The problem is that repmat converts '' to []
I want it to be ''
Is there a better way to do this?
  1 comentario
Aditya Jain
Aditya Jain el 30 de Oct. de 2015
This happens only when I see it in Workspace Browser/ Viewer by double clicking a. Doesn't happen if I do ans(1,1).a
So probably a bug in Workspace browser?

Iniciar sesión para comentar.

Respuesta aceptada

Nitin Khola
Nitin Khola el 3 de Nov. de 2015
Thanks for bringing this to the fore. At this instance, this appears to be an issue with the variable editor and not "repmat". You have mentioned that in the comment and it can also be illustrated by:
>> structElement = struct('a', '', 'b', '', 'c', []);
>> RepSt = repmat(structElement, [4,1]);
>> ischar(RepSt(1,1).a)
ans =
1
>> ischar(RepSt(1,1).c)
ans =
0
I was able to reproduce this issue. I will add it to our records. On a side note, I would like to request you to not use "ans" as a variable. Using the reserved keywords as variable and function names should be avoided.
  1 comentario
Aditya Jain
Aditya Jain el 11 de Nov. de 2015
was just using that to reproduce the issue. Thanks for the tip :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by