i want to write shorter code
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuesta aceptada
Voss
el 1 de Sept. de 2023
b=[0 1 1 0 0]
b|b.'
2 comentarios
Voss
el 1 de Sept. de 2023
Editada: Voss
el 1 de Sept. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Type Identification en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!