필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
When I type the following commands:
[X,Y] = meshgrid(0:.2:1, 0:.2:1);
surf(X,Y,mFunction(X,Y))
matlab gives me the following error :
In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in mFunction (line 40)
L(i)=alpha.*MS3(i)+(1-alpha).*L(i-1);
How should I proceed? Thanks!
  댓글 수: 1
Image Analyst
Image Analyst 2016년 7월 4일
How are X and Y being used in mFunction? You're not showing that. Also, what is the value of i and alpha when it errors? By the way, do you know how to use the debugger?

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

채택된 답변

Walter Roberson
Walter Roberson 2016년 7월 4일
Your function is not vectorized. You will need to use
Z = arrayfun(@mFunction, X, Y);
surf(X, Y, Z, 'edgecolor', 'none')
but it would be much more efficient to vectorize your function.
At the very least you should pull the xlsread() out of the function, assign the appropriate extracted values to a variable in the calling code, and have the calling code pass the value in to the function. xlsread() can be pretty slow.
  댓글 수: 3
Walter Roberson
Walter Roberson 2016년 7월 4일
I have no idea what it calculates or how, since the comments took a vacation and never came back. But I would point out, for example, that
L=zeros(288,1);
L(25)=MS3(25);
for i=26:264;
L(i)=alpha.*MS3(i)+(1-alpha).*L(i-1);
end
could be replaced by
numalpha = length(alpha);
L = zeros(288, numalpha);
L(25,:) = MS3(25);
for i = 26:264;
L(i,:) = alpha.*MS3(i) + (1-alpha).*L(i-1,:);
end
That would not be the only required change.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation of 2-D Selections in 3-D Grids에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by