why embedded matlab function failed to determine the size of expression

조회 수: 1 (최근 30일)
Hi all,
u is an input from the output of continous state.so, for each time (1 x 3) matrix will come out, so
u matrix = 1 x 3
Mean = 1 x 450
is a mean of samples.This input from workspace which consist 150 times with 3 variables so its matrix is (1 x 450). but we only need (1 x 3) matrix to evaluate for each time
Std = 1 x 450
is a standard deviation of samples.Same description as above(mean)
Xnew = 1x3
is an outpyt from the equation Xnew = u-mean/std
Example;
for time 1
Xnew = u-Mean(1,1:3)
time 2
Xnew = u-Mean(1,4:6);
untill time 150
i'm trying to do loop in embedded matrix function as below command:
function Xnew = stats(u,Mean, Std)
%#eml
for j=1:150,
Xnew = (u-Mean(1,j:j+2))./Std(1,j:j+2);
end
unfortunately i received this error,
"Could not determine the size of this expression"
I'm doing looping because i want to pick the submatrix that will be used in the equation.
What should i change above command so as i can get the result as i want? anybody have idea?
  댓글 수: 1
Jan
Jan 2012년 7월 18일
I have problems to determine the size of u also. Are u and Mean, Std and XNew different variables? Then please edit the question and brush up the formatting.
Does Matlab have a chance to know the size of u?
Is there a reason to overwrite XNew in each iteration of the for j loop?

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

채택된 답변

Kaustubha Govind
Kaustubha Govind 2012년 7월 18일
Strange. This works fine for me (I'm using R2011b). Perhaps you are using an older version of MATLAB? What about if you pre-allocate Xnew at the top of the function:
Xnew = zeros(1,3);
  댓글 수: 4
yana osman
yana osman 2012년 8월 6일
In my "from file" block does not have :data interpolation within time range" dialog. its only have "file name and "sample time". Any alternative step can i do to turn off linear interpolation? by the way i'm using MATLAB R2009a
Kaustubha Govind
Kaustubha Govind 2012년 8월 6일
Yana: Sorry, perhaps the option to turn off interpolation was only introduced in a later release. You could try using Inport blocks to import data - these blocks should have an "Interpolate data" checkbox which you can turn off.

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

추가 답변 (1개)

Fred Smith
Fred Smith 2012년 7월 18일
In more recent versions your code should just work. However, in older versions the size of this pattern was not understood:
j:j+2
Simply rewrite it as:
j + (0:2)
HTH,
Fred

Community Treasure Hunt

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

Start Hunting!

Translated by