필터 지우기
필터 지우기

Creating a logical array within a loop

조회 수: 3 (최근 30일)
Amy Hassett
Amy Hassett 2020년 4월 16일
댓글: Amy Hassett 2020년 4월 16일
I am trying to create a logical array in a loop, wherein each iteration of the loop should create a new column in my array:
for i= 1:size(Behaviours) %Behaviours is a 27x1 cell array containing strings
temp = strcmp(Shank2_KOs(k).BehaviourType, Behaviours(i)); %creates the logical vectors
temp_array = temp(:,i);
end
  댓글 수: 2
Rik
Rik 2020년 4월 16일
You are overwriting both variables every iteration. What do you want to store in which variable?
Amy Hassett
Amy Hassett 2020년 4월 16일
I would like to store the colum vector output of "temp" as a new column in "temp_array".

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

채택된 답변

Rik
Rik 2020년 4월 16일
In a loop the indexing works just as normal. I also made some other changes to your code.
temp_array=zeros(____,numel(Behaviours));
for n= 1:numel(Behaviours) %Behaviours is a 27x1 cell array containing strings
temp = strcmp(Shank2_KOs(k).BehaviourType, Behaviours(n)); %creates the logical vectors
temp_array(:,n) = temp;
end
  댓글 수: 1
Amy Hassett
Amy Hassett 2020년 4월 16일
That worked perfectly, thanks a million!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by