Python to Matlab property decorator function in class
8 ビュー (過去 30 日間)
古いコメントを表示
I have this piece of code in python that i want to translate to matlab. Any ideas how it could be done?
class Celsius:
def __init__(self, temperature = 0):
self._temperature = temperature
def to_fahrenheit(self):
return (self.temperature * 1.8) + 32
@property
def temperature(self):
print("Getting value")
return self._temperature
@temperature.setter
def temperature(self, value):
self._temperature = value
0 件のコメント
回答 (1 件)
Thibaut Jacqmin
2022 年 1 月 28 日
classdef Celsius < handle
properties
temperature
end
methods
function obj = Celsius(temperature)
arguments
temperature double = 0
end
obj.temperature = temperature;
end
function y = to_fahrenheit(obj)
y = (obj.temperature * 1.8) + 32;
end
function y = get.temperature(obj)
disp("Getting value")
y = obj.temperature;
end
function set.temperature(obj, value)
disp("Setting value")
obj.temperature = value;
end
end
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Call Python from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!