creating structure array into component structure into fields into vectors.

조회 수: 8 (최근 30일)
James Chang
James Chang 2016년 12월 7일
댓글: the cyclist 2016년 12월 7일
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.

답변 (1개)

the cyclist
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
James Chang
James Chang 2016년 12월 7일
Awesome! thank you ill try that out!
the cyclist
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 CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by