This video is old but at point 4:27 The reason why Matlab gives a 1x0 empty matrix is that whenever sum is given a 2D matrix. It sums all the elements in the columns So it gives [] If you do sum(a, 'all') It will return 0. In 0x2 matrix you have two columns hence the [0 0].
MATLAB is a programming language designed by mathematicians who have never used a real language, down to its godawful UI. My 2 favorite wats: #1 a = (1 2) a(4) = 4 The result in any other language would be an index error but here it is (1 2 0 4) #2 You can omit any number of 'end' statements. This bit me in an assignment where I ended a function but forgot to end a for loop, leading to the end applying to a for loop instead: function ... for ... (Do something repeatedly) (Do something once) end
+aestrivex I guess sum works column-wise, except when the height of the matrix is 1, in which case it's row-wise. So sum(zeros(0,2)) ist [sum([]), sum([])], while sum(zeros(2,0)) is zeros(1,0) + zeros(1,0) which works as normal vector addition, adding up all (so...0) values and resulting in a vector of the same size as the original two.
I spent several years working on MATLAB (from 2007 to 2014, not counting university years), and then one day this happened: marcofoco.com/?p=22 After that, I decided to resign.
+Marco Foco I don't get the confusion. You made eval into a variable by setting the 67th position to 4. (The char 'C' is 67...in all languages I know).
It sound perfectly reasonable that you can overload a built-in function, and completely prevent the function to be called. Silly me for spending all those years studying software engineering...
This video is old but at point 4:27
The reason why Matlab gives a 1x0 empty matrix is that whenever sum is given a 2D matrix. It sums all the elements in the columns
So it gives []
If you do sum(a, 'all')
It will return 0.
In 0x2 matrix you have two columns hence the [0 0].
Great video! I have used Matlab for years, and I still learn new things about it every day!
Actual Wat starts at 4:00
MATLAB is a programming language designed by mathematicians who have never used a real language, down to its godawful UI.
My 2 favorite wats:
#1
a = (1 2)
a(4) = 4
The result in any other language would be an index error but here it is (1 2 0 4)
#2
You can omit any number of 'end' statements. This bit me in an assignment where I ended a function but forgot to end a for loop, leading to the end applying to a for loop instead:
function ...
for ...
(Do something repeatedly)
(Do something once)
end
I just got this recommended out of nowhere. 🤔 But only a JavaScript WAT can top this video. xD
Most of the odd semantics in the video are well explained, but does anyone have any idea why sums of empty matrices works like this?
+aestrivex I guess sum works column-wise, except when the height of the matrix is 1, in which case it's row-wise.
So sum(zeros(0,2)) ist [sum([]), sum([])], while sum(zeros(2,0)) is zeros(1,0) + zeros(1,0) which works as normal vector addition, adding up all (so...0) values and resulting in a vector of the same size as the original two.
I spent several years working on MATLAB (from 2007 to 2014, not counting university years), and then one day this happened:
marcofoco.com/?p=22
After that, I decided to resign.
+Marco Foco That's pretty great.
+Marco Foco I don't get the confusion. You made eval into a variable by setting the 67th position to 4. (The char 'C' is 67...in all languages I know).
It sound perfectly reasonable that you can overload a built-in function, and completely prevent the function to be called.
Silly me for spending all those years studying software engineering...
Fragged guy ivy theft
1:25 WROOOONG, you NEVER get used to a 1 indexed language, NEVER EVER EVER EVER!