Hello, I am using in Simulink the "Matlab Function" block. The function in there is "diff(u)" This is just an example, the original function is much more complex. When I execute my simulation I get this error: Error in 'untitled/MATLAB Fcn'. Evaluation of expression resulted in an invalid output. Only finite double vector or matrix outputs are supported
What is the problem here?

댓글 수: 1

David
David 2016년 3월 18일
it is really unfortunate that no one from MATLAB has taken answering question on this forum seriously.

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

 채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 12월 19일

0 개 추천

Take the default parameter for the "MATLAB Fcn" block for example, the MATLAB function is "sin" so it get sin(x) as output if the input is x. If you put your customized function as the parameter, for example, "MyFancyFunction", the output might be some cell array of strings, which is not supported in Simulink. That is what the error message is about.

댓글 수: 6

Frank
Frank 2011년 12월 19일
But diff(x) is a buildin Matlab-function. Text from help: "If X is a vector, then diff(X) returns a vector, one element shorter than X..." So both values are vectors. This shouldnt be the problem.
Or is there a problem with "one element shorter"?
Walter Roberson
Walter Roberson 2011년 12월 19일
What is the nature of the input signal you are passing to the block? Continuous? Discrete?
Fangjun Jiang
Fangjun Jiang 2011년 12월 19일
That is the difference between MATLAB and Simulink. In MATLAB, you have all the data at once so you can do diff. In Simulink, most time, signal value comes one at a time, the simulation goes as the time goes. I suspect that is the cause of your error, although I can't verify it now. If the input is one element, then you can't do diff on it. Try some other function, you probably won't see the error.
Walter Roberson
Walter Roberson 2011년 12월 19일
But diff() of a scalar should be empty, and [] is still finite size. Either the message is wrong or diff() of a scalar is not the problem being encountered.
Frank
Frank 2011년 12월 19일
As input signal to diff() I am using currently the simulation time (Clock).
I think Fangjun is right in Simulink diff just gets one value and from this vector it cant calculate the diff.
Thanks guys.
Fangjun Jiang
Fangjun Jiang 2011년 12월 19일
Yes. It is particular related to the diff() function. I also did an example. Connect a Constant block to the MATLAB Fcn block with diff. If the Constant value is 1, it got the same error message. If the Constant is a vector signal like 1:5, it runs without problem.

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

추가 답변 (0개)

카테고리

질문:

2011년 12월 19일

댓글:

2016년 3월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by