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
4 次查看(过去 30 天)
显示 更早的评论
%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 个评论
采纳的回答
Dennis
2018-9-21
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 个评论
更多回答(1 个)
Dimitris Kalogiros
2018-9-21
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Financial Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!