hi there so i'm about to return to uni and so i thought id brush up on my ole matlab skills before returning so i went back to basics. at the moment im going through previous exams and the question issued was.
(b) (15 marks) Write a matlab script which counts the number of primes less than or equal to an integer n, say, where $n=2,3,...,1000$ and stores the result in an array count(n).
for e.g. count(7) would take the value 4 as there are four primes (2,3,5,7) less than or equal to 7
so heres my code (im not actually being tested so im being a bit lenient at this stage)
sooo i have it accurately telling me the number of primes between 1 and n at least so far as i can tell. but it's not storing A,
now i assume (like i said, im quite rusty at this and it's taking longer than id like) that the reason why its not storing A is because im running a function and i'm missing a "store vector A for later use" command.
Further i know i could technically get around this by making it actually a script (like it asks admittedly) with a few inputs and prompts to do the same thing as a function but you know....learning and stuff.
any help would be greatly appreciated.


Functions only return what you tell them to in the first line; that is, when you write
function [outputs] = name(inputs)you specify what, in which order, you want to return.Here's how I'd write this function.
Why this? I give variable names that make sense in what they are storing, and I give the user the option to return the number of primes, the list of primes, or both. To return just the list of primes, the user types
[~, prime_list] = primesless(n)in the console. The character~supresses the output of the item in that position.