Crazy If statement Error

2 Ansichten (letzte 30 Tage)
Andrei Makarskiy
Andrei Makarskiy am 21 Okt. 2015
Kommentiert: Andrei Makarskiy am 21 Okt. 2015
I have the following code:
optionDirection='sell'; % buy sell
optionType='put'; % put call all
if (optionDirection == 'buy')
switch optionType
case 'put'
calc_put_options_change;
case 'call'
calc_call_options_change;
case 'all'
calc_call_options_change;
calc_put_options_change;
end
else
switch optionType
case 'put'
calc_sold_put_options_change;
case 'call'
calc_sold_call_options_change;
case 'all'
calc_sold_call_options_change;
calc_put_options_change;
end
end
What does this error mean??
Error using ==
Matrix dimensions must agree.
Error in calc_change (line 36)
if (optionDirection == 'buy')
P.S. Matlab never stops surprising me on almost every simple step. Seems like Matlab developers aren't looking for easy ways....

Akzeptierte Antwort

the cyclist
the cyclist am 21 Okt. 2015
Bearbeitet: the cyclist am 21 Okt. 2015
The == operation does a specific comparison that is not appropriate here. I think you'll find more success with either isequal or strcmp.
If your definition of "easy" is for every programming language to be syntactically equivalent, then you are doomed to disappointment. MATLAB syntax is obviously optimized to make certain things (especially matrix computations) fast and easy. Other things then have to be a bit less intuitive. There's just no way around that.
  1 Kommentar
Andrei Makarskiy
Andrei Makarskiy am 21 Okt. 2015
What can I say.... BDSM )) I found the way using Switch in both cases

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements 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!

Translated by