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 个)

N = length(n) is not doing anything, just a waste of time

1 个评论

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 的更多信息

提问:

2013-10-26

Community Treasure Hunt

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

Start Hunting!

Translated by