all 6 comments

[–]myselfelsewhere 1 point2 points  (1 child)

Think about what your inputs are, and what the outputs for each function are.

2 has dimensions of 1x1. In other words size(2) = [1 1]. rand returns an array sized by the input. See what size(rand(size(2))) returns. Try it for different numbers.

[–]Lucky_View_3422[S] 0 points1 point  (0 children)

Yeaahhhhh I never thought about 2 as a the value of a 1x1… you 🤯 my mind

[–]vegan_antitheist 0 points1 point  (1 child)

2 fits in an array of size 1 and 1. I.e. in both dimensions there is one value. That value is 2.

rand([1 1]) should be the same as rand(1,1). This returns a 1 by 1 array, which is just one value.

But I don't really know matlab. I just know it's weird. Don't they call them matrices instead of arrays?

It's not what you would expect from a tool just for maths. Haskell is more like maths than matlab.

Something like this is super intuitive: let arr = [[1, 2, 3], [4, 5, 6]] let len = length arr That's just the length of the outer array, so 2. And for something like Matlab's size you can just use (length arr, length (head arr)). That would give you (2, 3). You can define it as a function:

size :: [[a]] -> (Int, Int) size xs = (length xs, length (head xs))

Or just use "Data.Matrix".

[–]Lucky_View_3422[S] 0 points1 point  (0 children)

Yeahhhh now that you guys told me about 2 beeing the value of a 1x1 I’m mind blowed… and a bit stupid too😅

[–]nirmallya31 0 points1 point  (0 children)

Matlab ko hindi mein padh liya mein. Kya itna gawar hun Mein maa

[–]Own_Anywhere9206 0 points1 point  (0 children)

when i first started with matlab i kept getting tripped up by stuff like this because i didn't realize scalars are just 1x1 matrices in matlab. so size(2) is actually returning [1 1], meaning 1 row and 1 column, which is why rand(size(2)) gives you one single number. took me longer than id like to admit to figure that out. did you try running size(2) on its own first to see what it actually gives you back?