Converting numbers into logicals

Hi, I would need to convert matrix A into a 120x9 logical array (B). A is a 120x1 cell, and each row contains numbers 1-9 (number of numbers vary). So for example, if row 1 is [3; 5; 6;8], I would like B to reflect [0 0 1 0 1 1 0 1 0] in the first row. How may I code for this?
Thank you, appreciate any help! :)

 採用された回答

Stephen23
Stephen23 2020 年 2 月 24 日
編集済み: Stephen23 2020 年 2 月 24 日

0 投票

>> A = {[3;5;6;8],[2,3,5]}; % fake data
>> B = cell2mat(cellfun(@(v)ismember(1:9,v),A(:),'UniformOutput',false))
B =
0 0 1 0 1 1 0 1 0
0 1 1 0 1 0 0 0 0

1 件のコメント

Cside
Cside 2020 年 2 月 24 日
thank you stephen, worked beautifully!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

質問済み:

2020 年 2 月 24 日

編集済み:

2020 年 2 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by