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!
