How to create a matrix with a for- loop

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

답변 (2개)

KSSV
KSSV 2021년 7월 1일

0 개 추천

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 2021년 7월 1일

0 개 추천

Check with this
n=3;
B=zeros(n);
for ii=1:n
for jj=1:n
B(ii,jj)=rem(ii,2);
end
end

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2021년 7월 1일

답변:

2021년 7월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by