Info

此问题已关闭。 请重新打开它进行编辑或回答。

Help with making a class

1 次查看(过去 30 天)
Anders
Anders 2013-8-26
关闭: MATLAB Answer Bot 2021-8-20
Hello, im pretty new at matlab, and im trying to make a class.
In the class i need to register some temperatures (unknown how many). I need to count them, find the max temperature, and i need to add some more temperatures after finding these.
This is what it has come to this far, but not working (of cause, not finished at all)
But can anybody help me.
classdef Maalinger < handle properties Temperaturskema end methods function obj = Maalinger() end function registrer(obj, temperatur) obj.Temperaturskema = temperatur; end function count() obj.Temperaturskema = number(m); end function max(obj) obj.Temperaturskema = max(m); end function
end
end

回答(1 个)

Simon
Simon 2013-8-26
Hi!
Your temperature property should be a vector. By adding temperature values with your "registrer" function you add the new value like in normal matlab syntax
obj.Temperaturskema = [obj.Temperaturskema; temperatur]
You get the count by saying
function count(obj)
fprintf('Number of temperature values: %d', length(obj.Temperaturskema))
end
Likewise for min/max:
function max(obj)
fprintf('Maximum temperature value: %f', max(obj.Temperaturskema))
end
HTH

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by