how to loop a whole program 100 times to get a single output

Please can anyone help with syntax to loop the program below a 100 times to get a single output T from T = TB*T where TB is TB*TB*TB*TB upto 100TB
f = 25 ;
T = eye(2);
m = 10;
Zcb = 104.5;
l = 3.75e-3 ;
Zo = (1 + (0.055*(1-1i))/sqrt(f));
n = 800 ;
x = 1;
P = 800;
Z1 = 1+((m)*sin(2*pi*n*x/P));
ZB = abs(Zcb*Zo*Z1);
u = ((494)+(36/f))*1.0e-9;
Vpk = 100/u ;
Attk = (1.80*sqrt(f)+ 0.005*(f)+ 0.25/sqrt(f));
Qk = ((Attk)*(0.01))/(8.68588963807);
Bk = (2*pi*f*1.0e6)/(Vpk);
Yk =(Qk + 1i*Bk);
H = (1.0000 + 0.0000i);
N = (0.0000 + 0.0029i);
Ds = (2*ZB.*Zo*H) + ((ZB.^2+Zo^2)*N);
SB11 = ((ZB.^2-Zo^2)*N)/Ds;
SB12 = (2*ZB.*Zo)/Ds;
SB21 = (2*ZB.*Zo)/Ds;
SB22 = ((ZB.^2-Zo^2)*N)/Ds;
% Program to convert S matrix to T matrix
TB11 = ((SB12*SB21)-(SB11*SB22))/SB21;
TB12 = (SB11/SB21);
TB21 = -(SB22/SB21);
TB22 = (1/SB21);
TB = [TB11 TB12;TB21 TB22];
T = T * TB;
disp('Result of multiplication of all the matrices together is'), T

 Accepted Answer

Just make a script with a for loop and call that m-file from inside the loop.
for experiment = 1 : 100
anyOutput(k) = yourOtherMFile(anyInput); % Or whatever it's called.
end

4 Comments

I mean how to apply it directly to the program stated above. Thanks
Yes, I know. That's why I gave you the answer I did.
@Image Analyst and what if we need the same number of results(loop length), how we will get?
@marie lasz, I have no idea what you're asking. "The same number" as what? "How we will get"? By writing a for loop of course.

Sign in to comment.

More Answers (1)

What does "implement this program 100 times" mean? Image Analyst meant that calling it 100 times would be sufficient. But perhaps this is a kind of imposition, Romanes eunt domus...
So perhaps you need a copy&paste to duplicate it 100 times?
But this sounds too strange also. So please explain, what the 100 implementations should do differently from calling the original version 100 times.

3 Comments

What I intend to do is loop the whole program a 100 times to get 100 outputs of TB which is then multiplied together i.e T= TB*TB*TB*TB upto 100th TB.The program is shown above.
Thanks
Then you can do
TB = 1;
for experiment = 1 : 100
anyOutput(k) = yourOtherMFile(anyInput); % Or whatever it's called.
TB = TB * anyOutput(k);
end
@Segun: Follow Image Analyst's solution. It is sufficient and clear.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!