MATLAB: How to solve “Subscripted assignment dimension mismatch” error .. line(68) wi(:,n)=w; .

)n)=w;wi(:

what is wrong in the statement. ?
wi(:,n)=w;
I am getting "Subscripted assignment dimension mismatch" error

Best Answer

This error occurs when wi is initialized to certain dimensions and in loop while filling the matrix with wrong number of dimensions. Check the below code, which shows the error.
wi = zeros(10,5) ;
for n = 1:10
wi(:,n) = rand(11,1) ;
end
In the above wi is of size 10X5, but in loop I am filling first column with a vector of 11X1, so the error popped out.
You need to check the size of w and initialize wi properly. Else, you may go for cell.
wi = cell(1,5) ;
for n = 1:10
wi{n} = rand(randperm(10,1),1) ;
end