Counter on matlab using for loop -
this question has answer here:
i have provided function file similar question input vector of size 3. can try running it.
function neha(limit) c = zeros(1,3); = 0:limit(3)-1 % same running 1:limit(3) c(3)=i; j = 0:limit(2)-1 c(2)=j; k=0:limit(1)-1 c(1)=k; x=3:-1:1 fprintf('%d ',c(x)) end fprintf('\n'); end end end return now question : create "counter" 0:limit-1. length of counter not determined in program , should determined when being run , inputs can differ each other. means input vector size not given , has work input 1,2 or 50. how make function file question? pls
i think understand question...try recursive function
function neha(limit,pointer) if nargin == 1 %first call pointer = 1; end = 1:limit(pointer) limit_ = limit; limit_(pointer) = i; if pointer == length(limit) fprintf('%d ',limit_-1); %print result fprintf('\n'); else neha(limit_,pointer+1); %run recursively end end end call neha(limit), don't have specify argument "pointer". hope helps.
Comments
Post a Comment