MATLAB: How to solve “Subscripted assignment dimension mismatch.” error?

arraysubscripted assignment dimension mismatch

Hi. I'm trying to write a piece of code with the follow objective: A cicle "for" that creates an array x with three binary numbers, convertes the binary to decimal number, and then saves the binary of each iteration in an diferent array called genes.
21: genes = [row, 3]
22: for r = 1:row
23: x = round(rand([1,3])) %Creates array with binary number
24: d = bi2de(x) %Convert binary to decimal
25: genes(r,:) = x %Saves binary number of each iteration
The error "Subscripted assignment dimension mismatch." keeps apearing on line 25. I've been trying to correct this for hours, i can't understand what i'm doing wrong. I have already tried to change the array genes on line 25 to genes(r, 3) but still returns an error. Sorry for my English it's not my first language

Best Answer

This should be
21: genes = nan([row, 3]);