Where was the empty array created?
2 次查看(过去 30 天)
显示 更早的评论
My understanding of classes: one of the roles of class properties is to store data.
When I run the following command,
x=Base.empty(7,0)
it shows that I've created a 7*0 Base array.
Qusetion:
1 So, is this 7*0 Base array stored in 'a,' ?in 'b'? or does 'a' and 'b' each have a separate 7*0 Base array? Why?
2 Is 'empty' a method or a function? This page shows it as a function. However, in OOP, aren't we supposed to use methods within classes? Why is 'empty' defined as a function and not a method?"
if you input mc=?Base; in command line , you will find mc.MethodList(3,1) is 'empty' method.
It seems like 'empty' is also a method, so is 'empty' actually a method or a function? Does MATLAB have the concept of class functions? If there are class functions, what is the difference between class functions and class methods?"
classdef Base
properties (Access=public)
a;
b;
end
methods
function obj=Base(value)
obj.a=value;
end
end
methods (Access=private)
function Fun(obj)
disp(num2str(obj.a));
end
end
end
0 个评论
采纳的回答
Bruno Luong
2023-8-20
编辑:Bruno Luong
2023-8-20
"1 So, is this 7*0 Base array stored in 'a,' ?in 'b'? or does 'a' and 'b' each have a separate 7*0 Base array? Why?"
This question has no sense to me.
The object (empty or not) never stored in its properties. And the second part of your question sounds like you see properties as object. They are not.
In this empty doc page one can read "empty is a hidden, public, static method of all nonabstract MATLAB® classes. You can override the empty method in class definitions."
So empty is a method.
Internally an array MATLAB objects has a meta data (mxArray structure) that stores the dimension and size of the array (among other thongs), and an array of data pointers that point to each internal representation element of the array. For empty array, one of the element of the size is 0 and the array pointer is NULL. It goes nowhere indicates there is NOTHING behind it.
There is not much sense to ask where an empty array is stored. It is not stored anywhere. Only the meta data remains and describing the class and size of the empty array.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!