Need help with factorizing array of numbers

5 views (last 30 days)
hi there,
say you have an array of numbers x =[94 89 124 120 150] how can i find factors of this array, i mean break each number in the array to its primes. i know the function is factor(x). but it only applies to a scalar value not an array. i tried putting it on a loop
x =[94 89 124 120 150] ;
for i = 1:length(x)
facts_x(i) = factor(x(i))
but this i realized gives me an error because the loop runs only in the length of x the facts_x ends up bigger because factor answer is stored as an array. please help. thanks SN
  1 Comment
José-Luis on 26 Feb 2013
Try storing it in a cell array instead:
facts_x(i) = {factor(x(i))}

Sign in to comment.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 26 Feb 2013
Edited: Azzi Abdelmalek on 26 Feb 2013
You need to use a cell array to store the result for each number, because they are not the same length
x =[94 89 124 120 150] ;
Azzi Abdelmalek
Azzi Abdelmalek on 27 Feb 2013
Jan, sorry for the confusion, I should have mentioned the name of the OP. I meant: don't add a comment as an answer.

Sign in to comment.

More Answers (1)

Ahsan Khan
Ahsan Khan on 27 Feb 2013
thanks for a quick reply. they both work but In either of those cases mentioned above how do i then store this in a single matrix?. thanx in advance. SN


Community Treasure Hunt

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

Start Hunting!