creating structure array into component structure into fields into vectors.
10 次查看(过去 30 天)
显示 更早的评论

So, I am not sure if my code is correct comparing from the diagram.
My Code
if true
voice = [1:100,000];
music_notes = {'DO' 'RE' 'MI' 'FA' 'SO' 'LA' 'TI'};
voice(1).pitch(1) = 1;
voice(1).start(1) = 1;
voice(1).duration(1) = 10;
% code
end
just did for voice(1) only.
0 个评论
回答(1 个)
the cyclist
2016-12-7
编辑:the cyclist
2016-12-7
To create the structure array, do
voice = struct();
instead of
voice = [1:100,000];
The latter code creates a vector, not a structure array.
Then the rest of your code should run fine. I can't remember if there is an advantage (or even a way) to pre-allocate the memory for a structure array. Maybe someone else could comment on that.
2 个评论
the cyclist
2016-12-7
The best form of thanks is to upvote and/or accept an answer, which rewards the contributor and points future users to helpful answers.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!