How do I store each output of my function as an vector element?

조회 수: 8 (최근 30일)
Pamela Stein
Pamela Stein 2014년 3월 12일
편집: Andrei Bobrov 2014년 3월 12일
I wrote a cross-ambiguity function (Function [tau,doppler,tau_p,doppler_p] = wgenx). There are no input arguments.
When I call my function in the command window, I get an output of four values.
I want to run my function 500 times and get 500 tau values, 500 doppler values, 500 tau_p values and 500 doppler_p values. But I want the 500 tau values in a vector (dimension 1 x 500) and 500 doppler values in a separate vector (dimension 1 x 500).
I am using on older 2010a student matlab version.
Help?

채택된 답변

Marta Salas
Marta Salas 2014년 3월 12일
편집: Marta Salas 2014년 3월 12일
I guess there are more efficient ways to do it, but have you try a simple for loop?
for i=1:150
[tau(i),doppler(i),tau_p(i),doppler_p(i)] = wgenx;
end

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2014년 3월 12일
편집: Andrei Bobrov 2014년 3월 12일
[tau,doppler,tau_p,doppler_p] = arrayfun(@wgenx,1:500);
ADD
[tau,doppler,tau_p,doppler_p] = arrayfun(@(x)wgenx,1:500);
  댓글 수: 2
Pamela Stein
Pamela Stein 2014년 3월 12일
I tried your suggestion in the command window. I receive "error using ==>wgenx, too may input arguments.
Suggestions? Thank you.
Andrei Bobrov
Andrei Bobrov 2014년 3월 12일
it for Octave, for MATLAB see ADD part

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by