新手:题目是“生成相量 A,其元素为区间[1,999]内的整数,然后找出 A 中能被 13 整除且 大于 500 的数。”
Show older comments
A=[1:999];
j=1;
i=A
for i=A
if A(i)>500;
if rem(A(i),13)==0;
C(j)=A(i);
j=j+1;
end
end
end
disp(C)
请问从if语句就开始不懂为什么用A(i),还有C(j)的意义是什么
1 Comment
新百胜游戏账号注册网址www.xbs0733.vip
on 3 Aug 2022
Answers (1)
用来把筛选的结果存在C向量里,代码有点冗余,可以参考:
C=[];
for i=500:999
if rem(i,13)==0
C=[C;i];
end
end
disp(C)
Categories
Find more on 编程 in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!