필터 지우기
필터 지우기

convert a logical matrix to the numeric one

조회 수: 3 (최근 30일)
som
som 2012년 4월 11일
Hi all; How can I convert a "logical matrix' to the numeric one. For example B matrix is below . I want to convert it to the B2 matrix . How can I do this without using any for loops?
B= [true true true true; false true true true; false false true true];
B2=[10 10 10 10; 5 10 10 10; 5 5 10 10]
Any help would be appropriated.

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2012년 4월 11일
in your case
B2 = B*5 + 5
OR
k = [5 10]
B2 = k(B + 1)
  댓글 수: 1
Jan
Jan 2012년 4월 11일
Or:
B2 = repmat(5, size(B));
B2(B) = 10;

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

카테고리

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