フィルターのクリア

Math operations incorrect GUIDE

1 回表示 (過去 30 日間)
qiana curcuru
qiana curcuru 2018 年 2 月 24 日
回答済み: Rik 2018 年 2 月 24 日
I am trying to draw a rectangle that has a width (lx) and length (ly) defined by user input with an edit text field using GUIDE. For some reason, the rectangle is not drawing correctly. Below I have the variables and corresponding values where X(1) and Y(1) is the location of the user's mouse click. For some reason, even though lx prints as the correct value, 2, when used in the equation X(1)-lx, lx suddenly becomes 50 and I have no idea why.
disp(lx)
disp(X(1))
disp(X(1)-lx)
disp(X(1)+lx)
2
299
249
349

採用された回答

Rik
Rik 2018 年 2 月 24 日
disp is hiding the fact that lx actually contains a char. If you do double('2') you will see the result is 50. To fix you calculations, use something like str2double.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by