0

If I have a MATLAB structure output like

f1: [0 0 0 0 0 0 0 0 0 0]
f2: 'a'

How can I feed this output to different structure without manually doing

F = struct('f1', [0 0 0 0 0 0 0 0 0 0], 'f2', 'a');

In other words I need to feed the data in format

'field' : value 

printed elsewhere in my live script notebook to a new structure. So far I am thinking about creating a binary file, but I thought there must be a better way.

Suever
  • 64,497
  • 14
  • 82
  • 101
stinglikeabeer
  • 455
  • 1
  • 3
  • 11

1 Answers1

0

Just reassign it to a new variable. This works since MATLAB utilize copy-on-write. Any changes to the new copy will not be reflected in the original.

F = struct('f1', [0 0 0 0 0 0 0 0 0 0], 'f2', 'a');
F2 = F;
Suever
  • 64,497
  • 14
  • 82
  • 101
  • Sorry, I don't think you understood my problem. I need to feed the data in format 'field' : value to a new structure. So far I am thinking about creating a binary file, but I thought there must be a better way. – stinglikeabeer Oct 01 '16 at 23:12
  • @belarus This *does* create a new structure...Maybe show an explicit example of what you want? – Suever Oct 01 '16 at 23:31
  • Ok, see the first section of the code in the question. How can you assign these fields and values separated by colon to a new structure? – stinglikeabeer Oct 01 '16 at 23:48
  • Oh so you didn't just print those from an existing structure? – Suever Oct 01 '16 at 23:48
  • @belarus You're trying to go from a *string* to a struct? Were those values ever in a struct? – Suever Oct 01 '16 at 23:54
  • Yes it was printed from a structure previously but I use that variable continuously so I do want to convert string to a structure. – stinglikeabeer Oct 02 '16 at 00:00
  • @belarus Why not just use the struct rather than the printed string? – Suever Oct 02 '16 at 03:15
  • I keep my lab notebook in matlab live script. I print fitting parameters as an output and keep it for my reference. Occasionally I need to go back and feed it to different fitting function. – stinglikeabeer Oct 02 '16 at 03:28