Creating a logical array within a loop

20 ビュー (過去 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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by