Avoid using for loop

조회 수: 1 (최근 30일)
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019년 10월 8일
답변: Srivardhan Gadila 2019년 10월 11일
I am using this like which works fine:
Cellcount=Acc.perhexagon(Ac.time==data.timepoints(end).time);
I want to get information not only from the last timepoint. I want to have info from zeor timepoint to final time point with the step of 2. 0, 2, 4, 6, ...,end or something like this: 0:2:end
What would be the easiest way?
  댓글 수: 6
Alaster Meehan
Alaster Meehan 2019년 10월 8일
Tru using arrayfun.
Something like:
Cellcount = Acc.perhexagon( arrayfun(@(x) (x.time == Ac.time), data.timepoints(1:2:end)) );
Note, because you are indexing an array you will need to start from 1 not 0.
structfun might also work.
Cheers Alaster
Daniel M
Daniel M 2019년 10월 8일
Note that arrayfun is just a for loop internally.

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

답변 (1개)

Srivardhan Gadila
Srivardhan Gadila 2019년 10월 11일
You may refer to arrayfun, structfun & splitapply.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by