Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Help with making a class

1 Ansicht (letzte 30 Tage)
Anders
Anders am 26 Aug. 2013
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
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

Antworten (1)

Simon
Simon am 26 Aug. 2013
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

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by