What is the need for having the 'length' code in this script?
Show older comments
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!
Answers (1)
Azzi Abdelmalek
on 26 Oct 2013
Edited: Azzi Abdelmalek
on 26 Oct 2013
0 votes
N = length(n) is not doing anything, just a waste of time
1 Comment
Walter Roberson
on 26 Oct 2013
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.
Categories
Find more on Variables 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!