Hi all,
I'm doing a spacecraft link budget analysis in MATLAB. I have a function that calculates the link margin, which I call in a main script. As I wish to limit the margin to a certain range I use a While Loop that alters the transmission power (P_t) until the condition is satisfied.
P_t=5;
flag_para=0;
flag_helix=0;
flag_horn=0;
flag_array=1;
S=S_epsilon*1000;
R_b=20e+6;
BER=8e-6;
dl=3;
A=0.1; % phase array
D_t=0; % Parabolic
eta=0.7;
f_t=8e+9;
lamda=3e+8/f_t; % Operating Wavelength in metres
L_com=0; % horn
margin=-inf;
j=1;
while margin<6 && margin>12
[margin,M_com,P_com,L_ant]=comm_payload(flag_para,flag_helix,flag_horn,flag_array...
,P_t,eta,lamda,D_t,f_t,L_com,A,S,dl,R_b,BER);
if margin<6
P_t=P_t*1.1;
j=j+1;
elseif margin>12
P_t=P_t*0.9;
j=j+1;
end
end
This doesn't seem to be working. The code runs but J stays at 1 and the margin also remains at -inf. Any ideas what is wrong? The function 100% works, tested it many times without the while loop.
Cheers

 채택된 답변

Voss
Voss 2024년 5월 7일
편집: Voss 2024년 5월 7일

0 개 추천

It's not possible for a number to be simultaneously less than 6 and greater than 12:

while margin<6 && margin>12

Did you mean this (less than 6 OR greater than 12)?

while margin<6 || margin>12

댓글 수: 2

Benjamin
Benjamin 2024년 5월 7일
Ohhhh, I'm an idiot! Thank you very much! I knew it was something stupid like that.
Voss
Voss 2024년 5월 7일
You're welcome!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

릴리스

R2023a

태그

질문:

2024년 5월 7일

편집:

2024년 5월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by