i want to write shorter code
3 次查看(过去 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!