i want to write shorter code
조회 수: 2 (최근 30일)
이전 댓글 표시
b=[0 1 1 0 0]
n=numel(b);
c=b'
repmat(b,n,1)
repmat(c,1,n)
repmat(b,n,1)|repmat(c,1,n)
댓글 수: 0
채택된 답변
Voss
2023년 9월 1일
b=[0 1 1 0 0]
b|b.'
댓글 수: 2
Voss
2023년 9월 1일
편집: Voss
2023년 9월 1일
@Luca Re: In case you are interested in the difference:
% when b is real,
b = [0 1 1 0 0];
% b' (complex conjugate transpose) and b.' (transpose) are the same
isequal(b',b.')
% when b is non-real,
b = [0 1i 1 0 0];
% b' and b.' are different
isequal(b',b.')
% but it doesn't matter in this case because | (or) can't deal with
% non-real operands
try
b|b'
catch e
disp(['error: ' e.message])
end
try
b|b.'
catch e
disp(['error: ' e.message])
end
% so for b|b.' (or b|b') to work, b must be real, in which case
% b.' is the same as b' as shown above
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Identification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!