Hello,
We want to create a new field in a structure, but we don't know how to do it..
Thanks!

回答 (2 件)

James Tursa
James Tursa 2016 年 12 月 1 日

0 投票

Not sure if this is what you are really asking:
mystruct.field1 = rand(1,3); % <-- Create a structure with field named field1
mystruct.field2 = rand(1,3); % <-- Add a new field2 to the existing structure

1 件のコメント

Joran Driesen
Joran Driesen 2016 年 12 月 1 日
Thanks! Actually this is our specific problem: We have a structure GRF.AdDB.Gait Now we want to add a field 'time', and the result has to be GRF.AdDB.Gait.time

サインインしてコメントする。

Image Analyst
Image Analyst 2016 年 12 月 1 日

0 投票

Just assign something to it. Like
GRF.AdDB.Gait.time = datestr(now);

3 件のコメント

Joran Driesen
Joran Driesen 2016 年 12 月 1 日
Thanks, But unfortunately we tried this and it doesn't work...
Steven Lord
Steven Lord 2016 年 12 月 1 日
Define "doesn't work". If it threw an error, show the full and exact text of the error message (don't omit anything, don't paraphrase) and show the size and class of GRF, GRF.AdDB, and GRF.AdDB.Gait. If it issued a warning, do the same as above but with the warning message instead of the error message.
Image Analyst
Image Analyst 2016 年 12 月 1 日
Here's proof it works:
Joran, tell us what "doesn't work" means. This link might help

サインインしてコメントする。

カテゴリ

タグ

質問済み:

2016 年 12 月 1 日

コメント済み:

2016 年 12 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by