Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

handling situations when properties are not always dependent

6 visualizaciones (últimos 30 días)
gareth
gareth el 23 de Abr. de 2012
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
I'm currently struggling with a situation where I've defined a class with dependent properties. In this case my class is a circuit with properties: voltage , current, and resistance. I use a get method to obtain the power of the circuit. The code can be seen as:
classdef circuit
%CIRCUIT Summary of this class goes here
% Detailed explanation goes here
properties
voltage
current
Resistance
end
properties (Dependent= true,SetAccess = private)
power
end
methods
function out = get.power(theCircuit)
out = theCircuit.current^2 * theCircuit.Resistance;
end
end
end
In this case I can dynamically get the power based on the current and the resistance properties.
My question is, what is the best way to handle situations when I want to define a power and resistance and from that use a getter method to obtain the current?
Any help is greatly appreciated!

Respuestas (0)

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by