Nested loops- not entering the second loop?

조회 수: 14 (최근 30일)
Anu Raghunathan
Anu Raghunathan 2021년 12월 11일
댓글: Anu Raghunathan 2021년 12월 11일
m=2;
n=16;
A = zeros(m*n,m*n);
b = zeros(m*n,1);
%interior points
for i=2:n-1
disp('first loop:');
disp(i);
for j=2:m-1
disp('second loop:');
disp('im here!!');
A(i*j,m-(i*j))= -4;
end
end
first loop:
2
first loop:
3
first loop:
4
first loop:
5
first loop:
6
first loop:
7
first loop:
8
first loop:
9
first loop:
10
first loop:
11
first loop:
12
first loop:
13
first loop:
14
first loop:
15
I'm trying to populate A with values at certain indeces. For some reason, I am not able to even enter the second loop. I can't understand what's going on here, can someone help me?
  댓글 수: 2
Torsten
Torsten 2021년 12월 11일
Since m=2, the second loop goes from 2 to 1, thus is never entered.
Anu Raghunathan
Anu Raghunathan 2021년 12월 11일
Oh my god thank you so much.... what a ridiculous error!! Thank you!

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by