How do i use vectors as input to the "interpreted Matlab Fnc" block?

조회 수: 1 (최근 30일)
I wrote a litle test function, which determines the scalar product of two vectors. It works fine when i use it in matlab. When i use the "interpreted Matlab Fnc" block in simulink it doesnt work properly. For a = 2 and b = 1 it gives me 2, which is correct. But when i use vectors instead of numbers like a = [2;2] and b = [1;1] i get 2 instead of 4.
I tried different combinations, but its always wrong... Since the "interpreted Matlab Fnc" block has only one input-port im using a Mux-block, may this be my mistake?
Does anybody have an idea what i'm doing wrong? thx for your help

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 4월 30일
a should be [2 2] instead of [2;2]
  댓글 수: 4
Fedor
Fedor 2013년 4월 30일
편집: Fedor 2013년 4월 30일
but thats not how i calculate the product in my function. I wanted to write my own code to test the "interpreted Matlab Fnc" block, because i will need it a lot. so my function is so:
function [ y ] = skalar( x,z )
y = 0;
if length(x) == length(z)
for i = 1:length(x)
y = y + x(i)*z(i);
end
else
print('Invalid Input');
end
end
i think the mistake must be in simulink, since the function works just fine when i use it in the workspace.
Kaustubha Govind
Kaustubha Govind 2013년 5월 9일
Fedor: it might be a good idea to set a breakpoint in your code to understand how the inputs are passed in.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Environment Customization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by