필터 지우기
필터 지우기

rectify the error in the code below

조회 수: 4 (최근 30일)
Elysi Cochin
Elysi Cochin 2014년 11월 17일
댓글: Guillaume 2014년 11월 18일
number of rows in b = 10;
I want to subtract each row of b with a i get... number of columns in both 'a' and 'b' are 128....
on some evaluation i get a as zero... that time when i execute the below code i get error
for i = 1 : size(b,1)
X(i,1) = sum(w * ((a(1,:) - b(i,:)).^2) / (a(1,:) + b(i,:)));
end
my error is
??? Error using ==> mtimes
Inner matrix dimensions must agree.
Error in ==> DemoFile at 147
X(i,1) = sum(w * ((a(1,:) - b(i,:)).^2) / (a(1,:) + b(i,:)));
why am i getting the error... please can someone rectify it... i want the code to work even if the value of a is zero and sort the matrix X....
please can someone rectify it for me...

채택된 답변

Guillaume
Guillaume 2014년 11월 17일
The error is with the multiplication. Is your w scalar?

추가 답변 (1개)

Roger Stafford
Roger Stafford 2014년 11월 17일
If 'w' has more than one column, you will get an error because
w * ((a(1,:) - b(i,:)).^2)
is performed before the division.
However, I suspect you meant to write
w .* ((a(1,:) - b(i,:)).^2) ./ (a(1,:) + b(i,:))
if 'w' is a row vector with 128 columns or
w * ((a(1,:) - b(i,:)).^2) ./ (a(1,:) + b(i,:))
if it is a scalar.
  댓글 수: 1
Guillaume
Guillaume 2014년 11월 18일
I thought at first that the division was meant to be element-wise as well. But the result is assigned to a scalar ( X(i, 1)), so it has to be a matrix division.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Semiconductors and Converters에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by