Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

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

2 Ansichten (letzte 30 Tage)
Chamira Wickramasinghe
Chamira Wickramasinghe am 11 Feb. 2016
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
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

Antworten (1)

Jan
Jan am 11 Feb. 2016
Bearbeitet: Jan am 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)).';

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by