Resources for OOP in Matlab.

1 view (last 30 days)
Hi,
I started looking into OOP matlab, and I'm fairly confused.
Could you share any useful resaurses to help me learn the classes within matlab?
Below I have a demonstration of what I'm trying to do, if you think the resoucrse I might need are specific. But, other than that it can be ignored.
Overall, the resources I found are very vain, don't have enough code examples, or jump too far ahead for starting to learn. Using matlab 2019a.
Currently I'm trying to make a programs into which you input a value you want find, let sat 'Velocity2', and input a range of known value by the use of an specific equation.
The equation is the Energy balance for steady flow: Q1-Q2+W1-W2=m(h2-h1 + V1^2/2 - V2^2/2 + g(z2-z1))
Where h2-h1 can be replaced with cp(t2-t1) or g(z2-z1) can be replaced with GE, depending on what is imputed into the equation.
This means the program will ask you for:
Value to solve for:
what is the value for X:
In the second question you can answer a double to input a know value or assumption, or n saying it is unknown. This would change the value of an objects property to the said value or leave/change it to empty if n was inputted. However, I cannot get it to work yet as I'm struggling with the Object and classes part and I'm uncertin if I should use a method for somethin or not.
For example below is a set of code I have but it gives me one of two problems.
Data; % The Class name with properties inside it
props = properties(Data);
for iprop = 1:length(props)
thisprop = props{iprop};
R = input( "value for " + thisprop + "? ", 's');
if ((R ~= 'N') || (R ~= 'n')) && (isnumeric(double(R)))
Data.(thisprop) = double(R);
end
end
Problem one, if you enter the value 'n' it will still set the specific property value as 'n'. Whereas I would prefer it to be left empty or set to empty (not yet code the elseif).
Problem two, it does not go through all the value after 'n' or a larger number is written and gives the message:
"Operands to the || and && operators must be convertible to logical scalar values.
Error in Energy_equation (line 22)
if (((R ~= 'N') || (R ~= 'n')) && (isnumeric(double(R))))"
Once, again I'm mainly looking for resource rather than a specific solution.

Accepted Answer

Samatha Aleti
Samatha Aleti on 29 Apr 2020
Hi,
You may refer the following MATLAB document links to have a good understanding on developing classes in MATLAB:
Refer the following link to understand how to deal with dependent properties in MATLAB:
Hope this helps!

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!