Vectorization: incompatible sizes of arrays
2 views (last 30 days)
O is a matrix with n_p x n_o rows; P is a matrix with n_p rows. Both matrices have three columns.The second column in O should be filled with the average of two values in the second column of P: the first value at the row ip and the second value at randomly selected row.
counter = 0;
for ip = 1:n_p
for io = 1:n_o
counter = counter + 1;
O(counter,2) = (P(ip,2) + P(randi(n_p),2))/2;
I attempted to vectorize the code as:
ip = 1:n_p;
io = 1:n_o;
O(ip(:)+io(:),2) = (P(ip(:),2)+P(randi(n_p),2))/2;
I am receiving the following message: „Arrays have incompatible sizes for this operation“. Thank you for any suggestions.