From: adrianomeis03 on

hello,

I use matlab 4.2.
I am an italian student.
I am beginning to use matlab.
I have written this code:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear

NA=16;

SA_delta_dp_vet=zeros(NA/8,1);

sA_delta_dp_vet=[1 0];

for k=2:2:(NA/4)
SA_delta_dp_vet(k)=0;
for n=1:2:(NA/4-1)
SA_delta_dp_vet(k/2)=SA_delta_dp_vet(k/2)+sA_delta_dp_vet((n+1)/
2)*sin(2*pi*n*k/NA);
end;
end;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


I obtain:

SA_delta_dp_vet =[0.707 1.0000 0 0]


I have declared SA_delta_dp_vet with 2 cells.
Before the loop starts, SA_delta_dp_vet still has 2 cells.
Why has SA_delta_dp_vet 4 cells after the loop?

What is it wrong in the code?

Thanks,

adriano meis


From: someone on
"adrianomeis03(a)gmail.com" <adrianomeis03(a)gmail.com> wrote in message <22a46a4c-ba84-48a8-9d63-347de6a0b7d1(a)b23g2000yqn.googlegroups.com>...
>
> hello,
>
> I use matlab 4.2.
> I am an italian student.
> I am beginning to use matlab.
> I have written this code:
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>
> clear
>
> NA=16;
>
> SA_delta_dp_vet=zeros(NA/8,1);
>
> sA_delta_dp_vet=[1 0];
>
> for k=2:2:(NA/4)
> SA_delta_dp_vet(k)=0;
> for n=1:2:(NA/4-1)
> SA_delta_dp_vet(k/2)=SA_delta_dp_vet(k/2)+sA_delta_dp_vet((n+1)/
> 2)*sin(2*pi*n*k/NA);
> end;
> end;
>
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>
>
> I obtain:
>
> SA_delta_dp_vet =[0.707 1.0000 0 0]
>
>
> I have declared SA_delta_dp_vet with 2 cells.
> Before the loop starts, SA_delta_dp_vet still has 2 cells.
> Why has SA_delta_dp_vet 4 cells after the loop?
>
> What is it wrong in the code?
>
> Thanks,
>
> adriano meis
>

If you look at your for loop you have:
> for k=2:2:(NA/4)
> SA_delta_dp_vet(k)=0;
So k = 2:2:4
and on the last iteration,
SA_delta_dp_vet(4)=0;

Perhaps you mean:
> for k=2:2:(NA/4)
> SA_delta_dp_vet(k/2)=0;




From: adrianomeis03 on
On 26 Apr, 19:50, "someone" <some...(a)somewhere.net> wrote:

> Perhaps you mean:
>
> > for k=2:2:(NA/4)
> >  SA_delta_dp_vet(k/2)=0;

ok,

thanks,

adriano