Info

This question is closed. Reopen it to edit or answer.

In an assignment A(I) = B, the number of elements in B and I must be the same

1 view (last 30 days)
whenever i execute following code it gives an error "In an assignment A(I) = B, the number of elements in B and I must be the same.". How can i overcome the problem?
for i = 1:3
mr_Ch(i) = (transpose(lab1_EEG(i,:))) - mean(transpose(lab1_EEG(i,1)));
end

Answers (1)

Jan
Jan on 11 Feb 2016
Edited: Jan on 11 Feb 2016
This is a column vector:
temp1 = transpose(lab1_EEG(i,:)))
This is a scalar:
temp2 = mean(transpose(lab1_EEG(i,1)))
In consequence this is a column vector also:
temp3 = temp1 - temp2
Now you try to assign this vector to a scalar variable:
mr_Ch(i) = temp3
This must fail. What do you want to store in mr_Chi? We cannot guess, what you want to achieve. But perhaps this helps - without a loop:
mr_Chi = bsxfun(@minus, lab1_EEG, mean(lab1_EEG, 1)).';

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!