user1661303
user1661303

Reputation: 539

Arrayfun problems in matlab

I'm trying to do a simple speed test in Matlab. I want it to factor 3^a-2 for each a from 1 to 20. Might be I'm choosing too small numbers here to see any significant difference, but I'm stuck anyway.

I tried to write

n = [1:20]
m = 3.^n-1
arrayfun(factor,m)

this gives a "not enough input parameters" error. I though it made sense but apparently not. After looking at some examples of arrayfun and the manual, i also tried

arrayfun(@(m)factor(m), m)
arrayfun(@(m), factor(m), m)
arrayfun(@factor, m)

but none worked. What's the correct way to do it? And also if I do speed tests of this sort, will the results be cached so I will have to use different numbers if I do the test again?

Upvotes: 1

Views: 207

Answers (1)

P0W
P0W

Reputation: 47784

Use this :

l=arrayfun(@factor,m, 'UniformOutput', false);

To access use :

l{1}, l{2}...etc

Upvotes: 1

Related Questions