- Background of the Issue
I ask a question What situations do we need to use the empty
method? What benefits does the empty
method provide?
I got an answer.But more answer more question.
This answer provides two reference questions :Difference between [] and [1x0] in MATLAB;Why can an empty array have a non-null dimension?(to avoid excessive clutter, only links are provided here).
These two reference questions and their answers have led to more contemplation and confusion for me. So, I posed this question in the hope that computer professionals could provide a more fundamental answer from the computer's lower levels (such as the operating system and memory.), allowing amateurs like me to understand what exactly happens in computer memory.
- Question
See this: What situations do we need to use the empty
method? What benefits does the empty
method provide?
When executing A = ColorInRGB.empty(5,0);
Did I get five empty rooms?
When I execute A = ColorInRGB.empty(5, 0)
, it shows that A's memory usage is 0. However, when I execute A = ColorInRGB.empty(1000000000000000000000000000, 0)
, it prompts an error: Error using ColorInRGB.empty. Requested array exceeds maximum variable size.
Since the created A has a memory usage of 0, why does it give an out-of-memory error when increasing the number of rows? why the computer provides an n×0 empty. what situations should I need to use an n×0 empty?
- Another Related Question
Especially this answer, why does b*a
result in []
?
why does a*b
result in 0
?
I'm not sure if the tags for this question are categorized correctly. If you find that the tags for this question are incorrect, please assign the correct tags to it(Except for the 'Matlab' Tag). Thank you.
2023/08/29
Thanks Martin Rosenau.This is a follow-up question regarding Martin Rosenau's response.
1 I think Matlab will internally store something like this
-----I find this perspective very reasonable. I speculate whether MATLAB's built-in classes might have some built-in hidden properties that the empty method cannot modify? Here are the reasons I've listed:
A=double.empty(5,0);
B=double.empty(0,5);
C=A*B
C =
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
However, when I create a class and use it to build an empty array, then multiply them...
classdef ColorInRGB<handle
properties
Color;
end
end
A=ColorInRGB.empty(5,0);
B=ColorInRGB.empty(0,5);
C=A*B
'ColorInRGB' 类型的操作数不支持运算符 '*'。
I speculate that the empty
method might be altering some properties of the object, causing the matrix multiplication to fail. However, I lack evidence. I wonder if there's a way to make the ColorInRGB
object capable of performing empty array multiplication, similar to how double objects can.
2、
Matlab will internally store something like this in this case
myVariable.dataType = 'double'
myVariable.numberOfDimensions = 2
myVariable.dimensions = [0 5]
myVariable.values = [ ]
---I think your speculation makes a lot of sense. Otherwise, it's hard to explain why the workspace shows the dimension of an empty array as 5*0. However, I've tried various methods and can't seem to find the dimension property for double objects. I'm not sure if there's another way.Here are the steps I've attempted:
A=double.empty(5,0);
properties(A)
mc=?A;
mc