필터 지우기
필터 지우기

Converting numbers into logicals

조회 수: 3 (최근 30일)
Cside
Cside 2020년 2월 24일
편집: Stephen23 2020년 2월 24일
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일
>> 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개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by