Creating a logical array within a loop

4 views (last 30 days)
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 Comments
Amy Hassett
Amy Hassett on 16 Apr 2020
I would like to store the colum vector output of "temp" as a new column in "temp_array".

Sign in to comment.

Accepted Answer

Rik
Rik on 16 Apr 2020
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 Comment
Amy Hassett
Amy Hassett on 16 Apr 2020
That worked perfectly, thanks a million!

Sign in to comment.

More Answers (0)

Categories

Find more on Cell Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!