Task: write matlab code for a class MinAngle which calculates the minimum angle between two bearings (bearing A and bearing B).

3 ビュー (過去 30 日間)
The class shall store the two bearings as properties: angleA and angleB.
Both of these shall be stored as private properties.
The class shall implement a method InputA(angle, type) which sets the value of angleA.
The method shall have two input arguments: angle and type.
If type is ‘radians’ then the unit for angle is radians and the angle shall be stored in angleA.
If type is ‘degrees’ then the unit for angle is degrees and the angle shall be stored in angleA.
If type is any other value then an error should be given with the message ‘ERROR1’.
This is what I have so far:
classdef MinAngle < handle
properties (SetAccess = private)
angleA;
angleB;
end
methods
function InputA(obj,angle,type)
if (type = 'radians')
if(angle > 2*pi || angle < 0)
error('angle not within range')
end
angledeg = rad2deg(angle);
obj.angleA = angledeg;
elseif(type = 'degrees')
if(angle > 360 || angle < 0)
error('angle not within range')
end
obj.angleA = angle;
end
end
end
Need help after this as I am stuck.

採用された回答

Steven Lord
Steven Lord 2021 年 3 月 3 日
The assignment operator in MATLAB is =. The element-wise comparison operator is ==. But you should use neither of those in your if statements.
if (type = 'radians')
Use text comparison functions instead, or perhaps use a switch / case statement.
Other than this, is there something else you are trying to do that has you stuck?
  7 件のコメント
Mubeen Ali
Mubeen Ali 2022 年 4 月 28 日
hello can I get the code of second part?
Mubeen Ali
Mubeen Ali 2022 年 4 月 28 日
can you send codes for both tasks?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSoftware Development Tools についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by