Python to Matlab property decorator function in class
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Thibaut Jacqmin
el 28 de En. de 2022
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 comentarios
Ver también
Categorías
Más información sobre Call Python from MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!