필터 지우기
필터 지우기

storing

조회 수: 1 (최근 30일)
nitya ...
nitya ... 2011년 3월 22일
for i=1:N-1
AF=AF+A(i)*2*cos((((2*(i-1))+1)/2)*w)
end
does N-1 values can be stored in the above code

답변 (2개)

the cyclist
the cyclist 2011년 3월 22일
AF = zeros(N-1,1);
for i=1:N-1
AF(i)=AF(i)+A(i)*2*cos((((2*(i-1))+1)/2)*w)
end
  댓글 수: 2
nitya ...
nitya ... 2011년 3월 22일
for i=1:N-1
A=input('enter A:')
end
if(mod(N,2)==0)
for i=1:N-1
AF=AF+A(i)*2*cos((((2*(i-1))+1)/2)*w)
end
in this code if AF read all the A(i) values
the cyclist
the cyclist 2011년 3월 22일
It is probably mostly a language barrier, but it is not clear what you want to do. Do you want to store all the cumulative sums, as you grow the values of AF? Then you could do what my code does (storing each intermediate value), then use the "cumsum" command to get the intermediate sums.
You need to write a longer, more detailed description of what you need, to get a good answer.

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


Matt Fig
Matt Fig 2011년 3월 22일
I would offer two criticisms of your code. First, you are using the built-in MATLAB variable i as a loop index. This will bite you later when you try to use it as the imaginary unit. Second, you should pre-allocate the variable AF instead of growing it in a loop:
AF = zeros(1,N-1) % Pre-allocation
for ii=1:N-1
AF(ii) = AF(ii) + A(ii)*2*cos((((2*(ii-1))+1)/2)*w);
end

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by