What is the need for having the 'length' code in this script?
显示 更早的评论
Hey all. So I'm currently going over some of the MATLAB content for one of my classes.
The question is: Write a MATLAB script to find all integers between 1 and 1000 that are divisible by 7 and have remainder 1 when divided by 2, 3, 4, 5, and 6
The answer they've given is:
n = 7:7:1000;
N = length(n)
for y=2:6
r = rem(n,y) ~= 1;
n(r) = [];
N = length(n)
end
n
My script is:
n= 7:7:1000;
for y=2:6
r= rem(n,y) ~= 1;
n(r)=[]
end
n
I received the same output for both of the above scripts, so what is the need for the 'N = length(n)' in the answer? And what is the purpose of it?
Any help would be appreciated!
回答(1 个)
Azzi Abdelmalek
2013-10-26
编辑:Azzi Abdelmalek
2013-10-26
0 个投票
N = length(n) is not doing anything, just a waste of time
1 个评论
Walter Roberson
2013-10-26
Notice that there is no semi-colon after the computation. The result will be displayed in the command window. What it is doing, then, is to give you a running feedback of the number of remaining candidates.
类别
在 帮助中心 和 File Exchange 中查找有关 Variables 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!