I have the following code:
for ii = 1: length(angles)
laminate.ply(ii).angle = angles(ii)/180*pi;
laminate.ply(ii).t = thickness(ii);
laminate.ply(ii).material = mat_ex3_ge();
end
How to impliment it without for/loop?

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2014년 5월 18일
편집: Andrei Bobrov 2014년 5월 18일

0 개 추천

laminate.ply = struct('angles',num2cell(angles(:)/180*pi),...
't',num2cell(thickness(:)),...
'material',repmat({mat_ex3_ge()},numel(angles),1));

댓글 수: 3

Dimitrios
Dimitrios 2014년 5월 18일
thanks :) Just to mention a small typing error in last line : the numel function.
Andrei Bobrov
Andrei Bobrov 2014년 5월 18일
Thank you, corrected.
Matt J
Matt J 2014년 5월 18일
편집: Matt J 2014년 5월 18일
Note, however, that this is not truly vectorized. The num2cell function uses for-loops,
>>type num2cell

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt J
Matt J 2014년 5월 18일

0 개 추천

There's no way without a for-loop or equivalent.
But regardless, it's a bad way to organize your data. It splits the angles(ii), thickness(ii), etc... data in an inefficient way. Store all data in one field instead,
laminate.ply.angles=angles*180/pi;
laminate.ply.t=thickness;
laminate.ply.material(1:length(angles))=mat_ex3_ge();

카테고리

도움말 센터File Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기

태그

질문:

2014년 5월 18일

편집:

2014년 5월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by