i want to write shorter code
3 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Voss
on 1 Sep 2023
b=[0 1 1 0 0]
b|b.'
2 Comments
Voss
on 1 Sep 2023
Edited: Voss
on 1 Sep 2023
@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
More Answers (0)
See Also
Categories
Find more on Data Type Identification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!