matlab的for循环和if条件语句下面代码为什么运行结果不对?
3个回答
展开全部
第二个end的位置不对,直接拖到最后一个end后面就可以了
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
A=[1 2 3;4 5 6;7 8 9];
for i=1:2
for j=1:2
if <a href="https://www.baidu.com/s?wd=abs&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9mW0knH63rH-Bnvw9PvnL0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6K1TL0qnfK1TL0z5HD0IgF_5y9YIZ0lQzqlpA-bmyt8mh7GuZR8mvqVQL7dugPYpyq8Q1DkP1RYPHf3n1czPWfznjcYnHb" target="_blank" class="baidu-highlight">abs</a>(A(i,j))<<a href="https://www.baidu.com/s?wd=abs&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9mW0knH63rH-Bnvw9PvnL0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6K1TL0qnfK1TL0z5HD0IgF_5y9YIZ0lQzqlpA-bmyt8mh7GuZR8mvqVQL7dugPYpyq8Q1DkP1RYPHf3n1czPWfznjcYnHb" target="_blank" class="baidu-highlight">abs</a>(A(i,j+1))
q=j+1
<a href="https://www.baidu.com/s?wd=end&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9mW0knH63rH-Bnvw9PvnL0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6K1TL0qnfK1TL0z5HD0IgF_5y9YIZ0lQzqlpA-bmyt8mh7GuZR8mvqVQL7dugPYpyq8Q1DkP1RYPHf3n1czPWfznjcYnHb" target="_blank" class="baidu-highlight">end</a>
if <a href="https://www.baidu.com/s?wd=abs&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9mW0knH63rH-Bnvw9PvnL0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6K1TL0qnfK1TL0z5HD0IgF_5y9YIZ0lQzqlpA-bmyt8mh7GuZR8mvqVQL7dugPYpyq8Q1DkP1RYPHf3n1czPWfznjcYnHb" target="_blank" class="baidu-highlight">abs</a>(A(i,j+1))<abs(A(i+1,j+1))
p=i+1
end
end
end
q =
2
p =
2
q =
3
p =
2
q =
2
p =
3
q =
3
p =
3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
A=[1 2 3;4 5 6;7 8 9];
for i=1:2
for j=1:2
if <a href="https://www.baidu.com/s?wd=abs&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9mW0knH63rH-Bnvw9PvnL0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6K1TL0qnfK1TL0z5HD0IgF_5y9YIZ0lQzqlpA-bmyt8mh7GuZR8mvqVQL7dugPYpyq8Q1DkP1RYPHf3n1czPWfznjcYnHb" target="_blank" class="baidu-highlight">abs</a>(A(i,j))<<a href="https://www.baidu.com/s?wd=abs&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9mW0knH63rH-Bnvw9PvnL0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6K1TL0qnfK1TL0z5HD0IgF_5y9YIZ0lQzqlpA-bmyt8mh7GuZR8mvqVQL7dugPYpyq8Q1DkP1RYPHf3n1czPWfznjcYnHb" target="_blank" class="baidu-highlight">abs</a>(A(i,j+1))
q=j+1
<a href="https://www.baidu.com/s?wd=end&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9mW0knH63rH-Bnvw9PvnL0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6K1TL0qnfK1TL0z5HD0IgF_5y9YIZ0lQzqlpA-bmyt8mh7GuZR8mvqVQL7dugPYpyq8Q1DkP1RYPHf3n1czPWfznjcYnHb" target="_blank" class="baidu-highlight">end</a>
if <a href="https://www.baidu.com/s?wd=abs&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9mW0knH63rH-Bnvw9PvnL0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6K1TL0qnfK1TL0z5HD0IgF_5y9YIZ0lQzqlpA-bmyt8mh7GuZR8mvqVQL7dugPYpyq8Q1DkP1RYPHf3n1czPWfznjcYnHb" target="_blank" class="baidu-highlight">abs</a>(A(i,j+1))<abs(A(i+1,j+1))
p=i+1
end
end
end
q =
2
p =
2
q =
3
p =
2
q =
2
p =
3
q =
3
p =
3
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
是不是数组越界了啊
j=n-1时
A(i,j+1)不会越界吗?
j=n-1时
A(i,j+1)不会越界吗?
追问
没有吧,n是A的列数,j=n-1时,A(i,j+1)=A(i,n)的啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询