I have a 300 x 150 zeros matrix and want to change only the lower triangular elements to 1, How do I do that?
23 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Daniel Gray
el 3 de Jul. de 2017
Editada: Image Analyst
el 17 de Mzo. de 2024
Everything is in the title really, I need to change the lower triangular elements of this zeros matrix to 1, how can I do this easily?
Respuesta aceptada
Image Analyst
el 3 de Jul. de 2017
Editada: Image Analyst
el 17 de Mzo. de 2024
You don't even need your original zeros matrix (let's say you called your original matrix "z") since it gets completely overwritten by 0's and 1's.
Simply make a 300 x 150 matrix of zeros with the lower left triangle of 1's like this:
z = [zeros(150); tril(ones(150), 0)];
% Now verify and display it.
size(z)
imshow(z)
axis('on', 'image')
0 comentarios
Más respuestas (3)
Abdurayimov Orzumurod
el 17 de Mzo. de 2024
idx = bir (300,150);
idx = tril(idx,1) ; % Pastki uchburchak qismiga 1 qo'ying
A = rand (300,150); % berilgan matritsa
A(idx==1) = 1 ; % pastki uchburchak qismini 1 bilan almashtiring
0 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing 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!