i want to write shorter code
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Voss
le 1 Sep 2023
b=[0 1 1 0 0]
b|b.'
2 commentaires
Voss
le 1 Sep 2023
Modifié(e) : Voss
le 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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Type Identification dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!