I am trying to create an if/else staement over a range of values and display the corresponding value for each values variable. Ex if a<5 then c=2 b=1 else c=3 b=4 but over a range of a values displaying each c or b value for each of the a values
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Brandon Pape
am 20 Sep. 2018
Beantwortet: Dennis
am 21 Sep. 2018
%I want to display each coa or cob value for each tp value of 0 through 1500 in 100 degree increments%
for tp=0:100:1500;
if tp<1600
coa=299180; cob=37.85; coc=-4571.9;
cooa=56835; coob=66.27; cooc=-11634;
hhoa=88923; hhob=49.36; hhoc=-7940.8;
ooa=43388; oob=42.27; ooc=-6635.4;
nna=31317; nnb=37.46; nnc=-4559.3;
else
coa=309070; cob=39.29; coc=-6201.9;
cooa=93048; coob=68.58; cooc=-16979;
hhoa=154670; hhob=60.43; hhoc=-19212;
ooa=127010; oob=46.25; ooc=-18798;
nna=44639; nnb=39.32; nnc=-6753.4;
end
0 Kommentare
Akzeptierte Antwort
Dennis
am 21 Sep. 2018
It is not 100% clear to me what you want to do, however you can use elseif for multiple statements:
a=5;
if a==4
elseif a==5
disp('This gets executed')
else
end
Instead of having a lot of ifelse statements it might be a better solution to use switch/case
a=5;
switch a
case 1
case 2
case 5
disp('This gets executed')
case 408954624
otherwise
end
Depending on what you are trying to do you might want to index your variables. This might help you later.
%coa for tp 100 to 1500
coa(1)=123456;
coa(2)=234567;
coa(3)=465791;
%...
tp=0:100:200;
for i=1:numel(tp)
disp(coa(i))
end
0 Kommentare
Weitere Antworten (1)
Dimitris Kalogiros
am 21 Sep. 2018
Dear Bardon,
At the code you gave us, tp never exceeds 1500, so regarding the if-statement, always the first part of it is executed.
Regards
0 Kommentare
Siehe auch
Kategorien
Mehr zu Financial Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!