Error using sum Dimension argument must be a positive integer scalar within indexing range.
显示 更早的评论
Hello, I am trying to do this calculation and despite the error message I am having trouble understanding the problem. I need help. Thank you from before.
N=11;
i=6;
Mrandom=round(mod(sum(rand(2^i),ones(2^N-i))),1)
回答(1 个)
Walter Roberson
2023-2-21
1 个投票
2^N-i is 2^11-6 = 2048 - 6 = 2042. ones(2042) is a 2D array that is 2042 x 2042 that is all ones. You are passing that 2042 by 2042 vector as the second element of sum(), into a position where sum() expects the list (unique) of dimension numbers to sum over. But a 2042 x 2042 array is not a vector, and the 1's in that array are not unique.
Note: rand(2^i) would be rand(2^6) which would ask for a 64 x 64 array of random numbers. That is not going to be compatible in size with the 2042 x 2042 array, so we can see that you are not asking to add the ones() and the rand() result.
Are you possibly trying to take randi([0 2^i-1], 2^N-i, 2^N-i) ?? But if so then the mod() would make the remainders all zero...
2 个评论
Willy Sean
2023-2-22
Walter Roberson
2023-2-22
That explanation confuses counting of random matrices with the actual random matrices, and is unclear what values are possible for the random matrices. If it wants to talk about iterating over all possible distinct 2^i by 2^i binary matrices then it should just do so instead of pretending that they are random.
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
