How to create a matrix with a for- loop

1 visualización (últimos 30 días)
Ángeles Herrera
Ángeles Herrera el 1 de Jul. de 2021
Respondida: Amit Bhowmick el 1 de Jul. de 2021
Hi, i'm trying to create a matrix using a for-loop and conditional.
I want to create
B= 1 1 1
0 0 0
1 1 1

Respuestas (2)

KSSV
KSSV el 1 de Jul. de 2021
A = zeros(3) ;
A(1,:) = 1 ;
A(3,:) = 1 ;
A
A = 3×3
1 1 1 0 0 0 1 1 1

Amit Bhowmick
Amit Bhowmick el 1 de Jul. de 2021
Check with this
n=3;
B=zeros(n);
for ii=1:n
for jj=1:n
B(ii,jj)=rem(ii,2);
end
end

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by