Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Creating loops

Subject: Creating loops

From: George

Date: 4 Dec, 2012 09:15:09

Message: 1 of 2

How could I go about creating a loop to do the following calculations?

paddedsig1=[zeros(1,l_hn-1),sig_pt1];
paddedsig2=[zeros(1,l_hn-1),sig_pt2];
paddedsig3=[zeros(1,l_hn-1),sig_pt3];
paddedsig4=[zeros(1,l_hn-1),sig_pt4];
paddedsig5=[zeros(1,l_hn-1),sig_pt5];
paddedsig6=[zeros(1,l_hn-1),sig_pt6];
paddedsig7=[zeros(1,l_hn-1),sig_pt7];
paddedsig8=[zeros(1,l_hn-1),sig_pt8];

FFTSIG1=fft(paddedsig1);
FFTSIG2=fft(paddedsig2);
FFTSIG3=fft(paddedsig3);
FFTSIG4=fft(paddedsig4);
FFTSIG5=fft(paddedsig5);
FFTSIG6=fft(paddedsig6);
FFTSIG7=fft(paddedsig7);
FFTSIG8=fft(paddedsig8);

Ypt1=FFTSIG1.*Hn5;
Ypt2=FFTSIG2.*Hn5;
Ypt3=FFTSIG3.*Hn5;
Ypt4=FFTSIG4.*Hn5;
Ypt5=FFTSIG5.*Hn5;
Ypt6=FFTSIG6.*Hn5;
Ypt7=FFTSIG7.*Hn5;
Ypt8=FFTSIG8.*Hn5;

Subject: Creating loops

From: Jos (10584)

Date: 4 Dec, 2012 10:44:09

Message: 2 of 2

If you convert the 8 different, yet related, variables into a cell array with 8 elements, (or a structure with 8 fields), life (or at least coding) will be very easy ...

sig_ptC = {sig_pt1 sig_pt2 ... sig_pt8} % conversion

for k=1:8,
  paddedsig{k} = [zeros(..) sig_ptC{k}] ;
  FFTSIG{k} = ...
  Ypt{k} = ...
end

hth

~ Jos

"George " <jorgmartnez@gmail.com> wrote in message <k9keut$13j$1@newscl01ah.mathworks.com>...
> How could I go about creating a loop to do the following calculations?
>
> paddedsig1=[zeros(1,l_hn-1),sig_pt1];
> paddedsig2=[zeros(1,l_hn-1),sig_pt2];
> paddedsig3=[zeros(1,l_hn-1),sig_pt3];
> paddedsig4=[zeros(1,l_hn-1),sig_pt4];
> paddedsig5=[zeros(1,l_hn-1),sig_pt5];
> paddedsig6=[zeros(1,l_hn-1),sig_pt6];
> paddedsig7=[zeros(1,l_hn-1),sig_pt7];
> paddedsig8=[zeros(1,l_hn-1),sig_pt8];
>
> FFTSIG1=fft(paddedsig1);
> FFTSIG2=fft(paddedsig2);
> FFTSIG3=fft(paddedsig3);
> FFTSIG4=fft(paddedsig4);
> FFTSIG5=fft(paddedsig5);
> FFTSIG6=fft(paddedsig6);
> FFTSIG7=fft(paddedsig7);
> FFTSIG8=fft(paddedsig8);
>
> Ypt1=FFTSIG1.*Hn5;
> Ypt2=FFTSIG2.*Hn5;
> Ypt3=FFTSIG3.*Hn5;
> Ypt4=FFTSIG4.*Hn5;
> Ypt5=FFTSIG5.*Hn5;
> Ypt6=FFTSIG6.*Hn5;
> Ypt7=FFTSIG7.*Hn5;
> Ypt8=FFTSIG8.*Hn5;

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us