**Info**

This question is closed. Reopen it to edit or answer.

# plotting the number of actions for ex i=i+1 ( action), pgd=n/i ( action), pgd=n(action)

3 views (last 30 days)

Show older comments

function pgd = entier(n)

i = 2;

while i≤n/2 & mod(n,i)~-0

i = i+1;

end

if mod(n,i)==0

pgd = n/i;

else

pgd = n;

end

end

##### 1 Comment

Roger Stafford
on 22 Jan 2014

### Answers (1)

AJ von Alt
on 21 Jan 2014

You can create a variable to count the number of actions taken and increment it every time an action is take. Have your function return that variable and store it for later plotting.

function [pgd , nActions] = entier(n)

nActions = 0;

i = 2;

while i<=n/2 && mod(n,i)~=0

i = i+1;

nActions = nActions + 1;

end

if mod(n,i)==0

pgd = n/i;

nActions = nActions + 1;

else

pgd = n;

nActions = nActions + 1;

end

end

##### 2 Comments

AJ von Alt
on 22 Jan 2014

### See Also

### Products

### Community Treasure Hunt

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

Start Hunting!