Save string in structure

19 次查看(过去 30 天)
Gennaro Arguzzi
Gennaro Arguzzi 2017-6-26
编辑: Stephen23 2017-6-26
Hi everyone. I'm trying to save string in a structure, but MATLAB shows me an error.
for i=1:3
file=strcat('Documento',num2str(i),' - by Gennaro');
struttura.nome(i)=file;
end
How can I do it?
Thank you very much.
  1 个评论
Stephen23
Stephen23 2017-6-26
编辑:Stephen23 2017-6-26
struttura.nome(i)
allcoates to one element of an array (the field nome). Presumably the strings has multiple elements, in which case this allocation will be an error. If you want to allocate a non-scalar char array (string) then you will need to use the correct indexing (e.g. using colon), or allocate by redefining that field entirely.

请先登录,再进行评论。

回答(1 个)

Gennaro Arguzzi
Gennaro Arguzzi 2017-6-26
Ok, I solved problem:
for i=1:3
file=strcat('Documento',num2str(i),' - by Gennaro');
struttura(i).nome=file;
end
Thank you anyway.

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by