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