Prosim o pomoc s podminkou
|
03-16-2013, 10:25
Príspevok: #1
|
|||
|
|||
Prosim o pomoc s podminkou
Ahoj prosim Vas o pomoc s nasledovnou castou programu:
elseif (Ees<120) ; Lz1_Dv1=(((((B1*((sin(HS_rad*pi/180))^C1)))/(((cos(HS_rad*pi/180))^D1))+(E1*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz2_Dv2=(((((B2*((sin(HS_rad*pi/180))^C2)))/(((cos(HS_rad*pi/180))^D2))+(E2*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz3_Dv3=(((((B3*((sin(HS_rad*pi/180))^C3)))/(((cos(HS_rad*pi/180))^D3))+(E3*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz4_Dv4=(((((B4*((sin(HS_rad*pi/180))^C4)))/(((cos(HS_rad*pi/180))^D4))+(E4*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz5_Dv5=(((((B5*((sin(HS_rad*pi/180))^C5)))/(((cos(HS_rad*pi/180))^D5))+(E5*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz6_Dv6=(((((B6*((sin(HS_rad*pi/180))^C6)))/(((cos(HS_rad*pi/180))^D6))+(E6*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); one=abs(Lz1_Dv1-Lzm_Dvm); two=abs(Lz2_Dv2-Lzm_Dvm); three=abs(Lz3_Dv3-Lzm_Dvm); four=abs(Lz4_Dv4-Lzm_Dvm); five=abs(Lz5_Dv5-Lzm_Dvm); six=abs(Lz6_Dv6-Lzm_Dvm); %hľadanie minima x_name=['1', '2', '3', '4', '5', '6']; [~, argx]=min([one, two, three, four, five, six]); sprava = x_name(argx); else Lz7_Dv7=(((((B7*((sin(HS_rad*pi/180))^C7)))/(((cos(HS_rad*pi/180))^D7))+(E7*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz8_Dv8=(((((B8*((sin(HS_rad*pi/180))^C8)))/(((cos(HS_rad*pi/180))^D8))+(E8*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz9_Dv9=(((((B9*((sin(HS_rad*pi/180))^C9)))/(((cos(HS_rad*pi/180))^D9))+(E9*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz10_Dv10=(((((B10*((sin(HS_rad*pi/180))^C10)))/(((cos(HS_rad*pi/180))^D10))+(E10*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz11_Dv11=(((((B11*((sin(HS_rad*pi/180))^C11)))/(((cos(HS_rad*pi/180))^D11))+(E11*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz12_Dv12=(((((B12*((sin(HS_rad*pi/180))^C12)))/(((cos(HS_rad*pi/180))^D12))+(E12*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz13_Dv13=(((((B13*((sin(HS_rad*pi/180))^C13)))/(((cos(HS_rad*pi/180))^D13))+(E13*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz14_Dv14=(((((B14*((sin(HS_rad*pi/180))^C14)))/(((cos(HS_rad*pi/180))^D14))+(E14*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz15_Dv15=(((((B15*((sin(HS_rad*pi/180))^C15)))/(((cos(HS_rad*pi/180))^D15))+(E15*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); seven=abs(Lz7_Dv7-Lzm_Dvm); eight=abs(Lz8_Dv8-Lzm_Dvm); nine=abs(Lz9_Dv9-Lzm_Dvm); ten=abs(Lz10_Dv10-Lzm_Dvm); eleven=abs(Lz11_Dv11-Lzm_Dvm); twelve=abs(Lz12_Dv12-Lzm_Dvm); thirteen=abs(Lz13_Dv13-Lzm_Dvm); forteen=abs(Lz14_Dv14-Lzm_Dvm); fifteen=abs(Lz15_Dv15-Lzm_Dvm); %hľadanie minima x_name=['7', '8', '9', '10', '11', '12', '13', '14', '15']; [~, argx]=min([seven, eight, nine, ten, eleven, twelve, thirteen, forteen, fifteen]); sprava = x_name(argx); o co ide: Ak mam podmienku Ees je menej ako 120 - vypocita hodnoty 1-6 a vyberie minimalnu hodnotu. To mi funguje. Co nefunguje je druha podmienka - pokial Ees je viac ako 120 vypocita hodnota 7-15 a potrebujem aby tak isto vypocitalo minimalnu hodnotu a vypisalo jedno z cisel 7-15. Tam som narazil na problem ze mi pise casto "0" myslim si ze je to z dovodu toho ze mi naprikald vyde vysledok minima na premennej eleven a to je v poradi 5 premenna a preto mi vypise cislo 0 namiesto 11. Pretoze je to nejako spojene s prvou podmienkou. Vie mi niekto poradit co s tym? ako to zapisat? aby mi v prvej podmienke vypisalo cislo 1-6 a pokial nebude platna tak z druhej podmienky cisla 7-15? Dakujem |
|||
03-16-2013, 12:51
Príspevok: #2
|
|||
|
|||
RE: Prosim o pomoc s podminkou
V takomto vyseknutom kode sa hlada chyba docela tazko, kedze ani nevieme ake hodnoty kde mozu byt. Nevidim teda ziadny dovod preco by to nemalo fungovat v tej druhej podmienke ak to funguje v tej podmienke (Ees<120) - aka je prva podmienka if ( ??? ) ?. Este by som skontroloval ci v prvom pripade ma vzdy argx hodnoty od 1 do 6 a v druhom od 1 do 9 a nie ine (aj ked pri nespravnom indexe by to vyhodilo chybu)...
a este by som navrhol to upravit a pouzivat viac polia(matice) nech nech sa tam zbytocne neopakuju rovnake riadky len s rozdielom indexu, toto mozno pomoze: Kód: elseif ( Ees < 120 ) |
|||
03-16-2013, 13:09
Príspevok: #3
|
|||
|
|||
RE: Prosim o pomoc s podminkou
toto je cely program:function [vysledok] = najnovsie(riadok)
LATIT=48.17; LONGIT=17.06; De=riadok(9); Ge=riadok(8); M=riadok(1); D=riadok(2); H=riadok(4); Dv=riadok(7); Lz=riadok(10); gamas=riadok(11); B1=54.63; C1=1; D1=0; E1=0; B2=12.35; C2=3.68; D2=0.59; E2=50.47; B3=48.3; C3=1; D3=0; E3=0; B4=12.23; C4=3.57; D4=0.57; E4=44.27; B5=42.59; C5=1; D5=0; E5=0; B6=11.84; C6=3.53; D6=0.55; E6=38.78; B7=21.72; C7=4.52; D7=0.63; E7=34.56; B8=29.35; C8=4.94; D8=0.7; E8=30.41; B9=10.34; C9=3.45; D9=0.5; E9=27.47; B10=18.41; C10=4.27; D10=0.63; E10=24.04; B11=24.41; C11=4.60; D11=0.72; E11=20.76; B12=23.00; C12=4.43; D12=0.74; E12=18.52; B13=27.45; C13=4.61; D13=0.76; E13=16.59; B14=25.54; C14=4.40; D14=0.79; E14=14.56; B15=28.08; C15=4.13; D15=0.79; E15=13.00; MIN=riadok(5); SEC=H+(MIN/60); DEC_stup=23.45*sind(29.7*M+0.98*D-109); DEC_rad=(23.45*pi/180)*sin((29.7*M+0.98*D-109)*pi/180); TIMCOR_stup=0.125*sind(0.98*D+29.7*M-32)+(0.165*sind(1.96*D+59.4*M-38)); TIMCOR_rad=(0.125*pi/180)*sin((0.98*D+29.7*M-32)*pi/180)+(0.165*pi/180)*sin((1.96*D+59.4*M-38)*pi/180); TRUEST=SEC+((4*(LONGIT-15))/60)-TIMCOR_stup; HA=15*TRUEST; HS_stup=asind(sind(LATIT)*sind(DEC_stup)-cosd(LATIT)*cosd(DEC_stup)*cosd(HA)); HS_rad=asin(sin(LATIT*pi/180)*sin(DEC_stup*pi/180)-cos(LATIT*pi/180)*cos(DEC_stup*pi/180)*cos(HA*pi/180)); Ees=((Ge-De)/(sin(HS_stup))); Lzm_Dvm=Lz/Dv; if (Lzm_Dvm>0.6); sprava='99'; elseif (Lzm_Dvm<0.05); sprava='99'; elseif (gamas<5); sprava='99'; elseif (Ees<120) ; Lz1_Dv1=(((((B1*((sin(HS_rad*pi/180))^C1)))/(((cos(HS_rad*pi/180))^D1))+(E1*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz2_Dv2=(((((B2*((sin(HS_rad*pi/180))^C2)))/(((cos(HS_rad*pi/180))^D2))+(E2*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz3_Dv3=(((((B3*((sin(HS_rad*pi/180))^C3)))/(((cos(HS_rad*pi/180))^D3))+(E3*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz4_Dv4=(((((B4*((sin(HS_rad*pi/180))^C4)))/(((cos(HS_rad*pi/180))^D4))+(E4*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz5_Dv5=(((((B5*((sin(HS_rad*pi/180))^C5)))/(((cos(HS_rad*pi/180))^D5))+(E5*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz6_Dv6=(((((B6*((sin(HS_rad*pi/180))^C6)))/(((cos(HS_rad*pi/180))^D6))+(E6*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); one=abs(Lz1_Dv1-Lzm_Dvm); two=abs(Lz2_Dv2-Lzm_Dvm); three=abs(Lz3_Dv3-Lzm_Dvm); four=abs(Lz4_Dv4-Lzm_Dvm); five=abs(Lz5_Dv5-Lzm_Dvm); six=abs(Lz6_Dv6-Lzm_Dvm); %hľadanie minima x_name=['1', '2', '3', '4', '5', '6']; [~, argx]=min([one, two, three, four, five, six]); sprava = x_name(argx); else Lz7_Dv7=(((((B7*((sin(HS_rad*pi/180))^C7)))/(((cos(HS_rad*pi/180))^D7))+(E7*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz8_Dv8=(((((B8*((sin(HS_rad*pi/180))^C8)))/(((cos(HS_rad*pi/180))^D8))+(E8*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz9_Dv9=(((((B9*((sin(HS_rad*pi/180))^C9)))/(((cos(HS_rad*pi/180))^D9))+(E9*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz10_Dv10=(((((B10*((sin(HS_rad*pi/180))^C10)))/(((cos(HS_rad*pi/180))^D10))+(E10*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz11_Dv11=(((((B11*((sin(HS_rad*pi/180))^C11)))/(((cos(HS_rad*pi/180))^D11))+(E11*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz12_Dv12=(((((B12*((sin(HS_rad*pi/180))^C12)))/(((cos(HS_rad*pi/180))^D12))+(E12*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz13_Dv13=(((((B13*((sin(HS_rad*pi/180))^C13)))/(((cos(HS_rad*pi/180))^D13))+(E13*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz14_Dv14=(((((B14*((sin(HS_rad*pi/180))^C14)))/(((cos(HS_rad*pi/180))^D14))+(E14*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz15_Dv15=(((((B15*((sin(HS_rad*pi/180))^C15)))/(((cos(HS_rad*pi/180))^D15))+(E15*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); seven=abs(Lz7_Dv7-Lzm_Dvm); eight=abs(Lz8_Dv8-Lzm_Dvm); nine=abs(Lz9_Dv9-Lzm_Dvm); ten=abs(Lz10_Dv10-Lzm_Dvm); eleven=abs(Lz11_Dv11-Lzm_Dvm); twelve=abs(Lz12_Dv12-Lzm_Dvm); thirteen=abs(Lz13_Dv13-Lzm_Dvm); forteen=abs(Lz14_Dv14-Lzm_Dvm); fifteen=abs(Lz15_Dv15-Lzm_Dvm); %hľadanie minima x_name=['7', '8', '9', '10', '11', '12', '13', '14', '15']; [~, argx]=min([seven, eight, nine, ten, eleven, twelve, thirteen, forteen, fifteen]); sprava = x_name(argx); end vysledok = [riadok(1), riadok(2), riadok(3), riadok(4), riadok(5), sprava]; dakujem za tipy, som v tom zaciatocnik. Vsetko mi funguje, ale urcite to prerobim podla tvojho navodu, nech tam nie je tolko opakovanych vzorcov. tu som nakopiroval programik s nejakymi realnymi cislami: LATIT=48.17; LONGIT=17.06; De=289; Ge=437; M=3; D=1; H=11; Dv=31573; Lz=5229; gamas=34.01; B1=54.63; C1=1; D1=0; E1=0; B2=12.35; C2=3.68; D2=0.59; E2=50.47; B3=48.3; C3=1; D3=0; E3=0; B4=12.23; C4=3.57; D4=0.57; E4=44.27; B5=42.59; C5=1; D5=0; E5=0; B6=11.84; C6=3.53; D6=0.55; E6=38.78; B7=21.72; C7=4.52; D7=0.63; E7=34.56; B8=29.35; C8=4.94; D8=0.7; E8=30.41; B9=10.34; C9=3.45; D9=0.5; E9=27.47; B10=18.41; C10=4.27; D10=0.63; E10=24.04; B11=24.41; C11=4.60; D11=0.72; E11=20.76; B12=23.00; C12=4.43; D12=0.74; E12=18.52; B13=27.45; C13=4.61; D13=0.76; E13=16.59; B14=25.54; C14=4.40; D14=0.79; E14=14.56; B15=28.08; C15=4.13; D15=0.79; E15=13.00; MIN=50; SEC=H+(MIN/60); DEC_stup=23.45*sind(29.7*M+0.98*D-109); DEC_rad=(23.45*pi/180)*sin((29.7*M+0.98*D-109)*pi/180); TIMCOR_stup=0.125*sind(0.98*D+29.7*M-32)+(0.165*sind(1.96*D+59.4*M-38)); TIMCOR_rad=(0.125*pi/180)*sin((0.98*D+29.7*M-32)*pi/180)+(0.165*pi/180)*sin((1.96*D+59.4*M-38)*pi/180); TRUEST=SEC+((4*(LONGIT-15))/60)-TIMCOR_stup; HA=15*TRUEST; HS_stup=asind(sind(LATIT)*sind(DEC_stup)-cosd(LATIT)*cosd(DEC_stup)*cosd(HA)); HS_rad=asin(sin(LATIT*pi/180)*sin(DEC_stup*pi/180)-cos(LATIT*pi/180)*cos(DEC_stup*pi/180)*cos(HA*pi/180)); Ees=((Ge-De)/(sin(HS_stup))); Lzm_Dvm=Lz/Dv; if (Lzm_Dvm>0.6); sprava='99'; elseif (Lzm_Dvm<0.05); sprava='99'; elseif (gamas<5); sprava='99'; elseif (Ees<120) ; Lz1_Dv1=(((((B1*((sin(HS_rad*pi/180))^C1)))/(((cos(HS_rad*pi/180))^D1))+(E1*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz2_Dv2=(((((B2*((sin(HS_rad*pi/180))^C2)))/(((cos(HS_rad*pi/180))^D2))+(E2*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz3_Dv3=(((((B3*((sin(HS_rad*pi/180))^C3)))/(((cos(HS_rad*pi/180))^D3))+(E3*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz4_Dv4=(((((B4*((sin(HS_rad*pi/180))^C4)))/(((cos(HS_rad*pi/180))^D4))+(E4*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz5_Dv5=(((((B5*((sin(HS_rad*pi/180))^C5)))/(((cos(HS_rad*pi/180))^D5))+(E5*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz6_Dv6=(((((B6*((sin(HS_rad*pi/180))^C6)))/(((cos(HS_rad*pi/180))^D6))+(E6*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); one=abs(Lz1_Dv1-Lzm_Dvm); two=abs(Lz2_Dv2-Lzm_Dvm); three=abs(Lz3_Dv3-Lzm_Dvm); four=abs(Lz4_Dv4-Lzm_Dvm); five=abs(Lz5_Dv5-Lzm_Dvm); six=abs(Lz6_Dv6-Lzm_Dvm); %hľadanie minima x_name=['1', '2', '3', '4', '5', '6']; [~, argx]=min([one, two, three, four, five, six]); sprava = x_name(argx); else Lz7_Dv7=(((((B7*((sin(HS_rad*pi/180))^C7)))/(((cos(HS_rad*pi/180))^D7))+(E7*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz8_Dv8=(((((B8*((sin(HS_rad*pi/180))^C8)))/(((cos(HS_rad*pi/180))^D8))+(E8*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz9_Dv9=(((((B9*((sin(HS_rad*pi/180))^C9)))/(((cos(HS_rad*pi/180))^D9))+(E9*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz10_Dv10=(((((B10*((sin(HS_rad*pi/180))^C10)))/(((cos(HS_rad*pi/180))^D10))+(E10*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz11_Dv11=(((((B11*((sin(HS_rad*pi/180))^C11)))/(((cos(HS_rad*pi/180))^D11))+(E11*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz12_Dv12=(((((B12*((sin(HS_rad*pi/180))^C12)))/(((cos(HS_rad*pi/180))^D12))+(E12*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz13_Dv13=(((((B13*((sin(HS_rad*pi/180))^C13)))/(((cos(HS_rad*pi/180))^D13))+(E13*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz14_Dv14=(((((B14*((sin(HS_rad*pi/180))^C14)))/(((cos(HS_rad*pi/180))^D14))+(E14*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); Lz15_Dv15=(((((B15*((sin(HS_rad*pi/180))^C15)))/(((cos(HS_rad*pi/180))^D15))+(E15*(sin(HS_rad*pi/180)))))/(133.8*(sin(HS_rad*pi/180)))); seven=abs(Lz7_Dv7-Lzm_Dvm); eight=abs(Lz8_Dv8-Lzm_Dvm); nine=abs(Lz9_Dv9-Lzm_Dvm); ten=abs(Lz10_Dv10-Lzm_Dvm); eleven=abs(Lz11_Dv11-Lzm_Dvm); twelve=abs(Lz12_Dv12-Lzm_Dvm); thirteen=abs(Lz13_Dv13-Lzm_Dvm); forteen=abs(Lz14_Dv14-Lzm_Dvm); fifteen=abs(Lz15_Dv15-Lzm_Dvm); %hľadanie minima y_name=['7', '8', '9', '10', '11', '12', '13', '14', '15']; [~, argy]=min([seven, eight, nine, ten, eleven, twelve, thirteen, forteen, fifteen]); sprava = y_name(argy); end nerozumiem preco je vyslesok "sprava" 0? ma byt 11 podla min. hodnoty. Vies mi poradit co je zle? Velmi pekne vopred dakujem za tvoj cas a ochotu |
|||
03-16-2013, 14:02
(Tento príspevok bol naposledy zmenený: 03-16-2013 14:03 od Larry.)
Príspevok: #4
|
|||
|
|||
RE: Prosim o pomoc s podminkou
aha uz to asi vidim, ta "0" je nula z tej '10', ak si vsimnes v ['7', '8', '9', '10', '11', '12', '13', '14', '15'] tak pre matlab je to zapisane takto : 789101112131415 a na 5. mieste je 0...
vyriesit by to mohlo napriklad nieco bud to ze pouzijes len cisla bez uvodzoviek, alebo spravis y_name = [' 7'; ' 8'; ' 9'; '10'; '11'; '12'; '13'; '14'; '15']; ! tu pozor pred 7,8 a 9 je medzera, lebo musia byt rovnakej dlzky (rozmery matice musia byt konzistentne) a potom na jeden cely string sa bude pristupovat napriklad takto: y_name( 5, : ) % na ziskanie '11'ky pripadne si este nastudovat nieco o String-och v matlabe |
|||
03-16-2013, 18:26
Príspevok: #5
|
|||
|
|||
RE: Prosim o pomoc s podminkou
Dakujem velmi pekne za radu, funguje to.
|
|||
|