call with matlabfunction(simulink) an other mfile

Hi, i have a simulink model, which computes a value, then i give this value to a matlab funktion, then fron this matlab funktion i wanna call an other mfile funktion and give this mfile function this value.
How can i call an other funktion and give a value???? THX

Respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 3 de Jun. de 2013

0 votos

9 comentarios

yes i did. maybe i should say more: The matlabfunction in simulink calls a mfile function, which is not in simulink, and this has already 4 inputs.
The matlabfunction in simulink is like that:
function y = load_handles(u)
%#codegen
y = test_environment(u);
end
and the head of the other function is that
function y = test_environment(i,d,c,alpha)
how can i add u into that????
Azzi Abdelmalek
Azzi Abdelmalek el 3 de Jun. de 2013
Editada: Azzi Abdelmalek el 3 de Jun. de 2013
function y = load_handles(i,d,c,alpha)
%#codegen
y = test_environment(i,d,c,alpha);
that is not right :(... because
load_handles(u)
get only one input "u"
I want only call this function:
function test_environment(i,d,c,alpha)
and put "u" into this.
And what are i,d,c,alpha ? constants or signals?
If they are constants, you can use Ports and Data Manager
actuelly the function looks like this :
function test_environment(i,d,c,alpha)
switch(nargin),
case 0
i = [5 5 5];
d= [1 1 1];
c= 'b';
alpha = 0.5;
case 1 ....
now i want call this function from matlabcunction in simulink and give the input "u" additionally.
Azzi Abdelmalek
Azzi Abdelmalek el 3 de Jun. de 2013
Editada: Azzi Abdelmalek el 3 de Jun. de 2013
You did not answer my question, what are i,d ,c and alpha constants or signals? how are they used in your simulink model?
they are constants for building a geimetry. i = [x y z] d = [dx dy dz] voxlesize c = color
I added my function into the matlabfunction, looks like this
function y = handle (u)
y = test_environment(u);
function y = test_environment(u)
switch(nargin),
case 0
i = [5 5 5];
d= [1 1 1];
c= 'b';
alpha = 0.5;
case 1
l=1; %default length of side of voxel is 1
c='b'; %default color of voxel is blue
case 2,
c='b';
case 3,
alpha=1;
case 4,
%do nothing
otherwise
disp('Too many arguements for voxel');
end;
x=[i(1)+[0 0 0 0 d(1) d(1) d(1) d(1)]; ...
i(2)+[0 0 d(2) d(2) 0 0 d(2) d(2)]; ...
i(3)+[0 d(3) 0 d(3) 0 d(3) 0 d(3)]]';
for n=1:3,
if n==3,
x=sortrows(x,[n,1]);
else
x=sortrows(x,[n n+1]);
end;
temp=x(3,:);
x(3,:)=x(4,:);
x(4,:)=temp;
h=patch(x(1:4,1),x(1:4,2),x(1:4,3),c);
set(h,'FaceAlpha',alpha);
temp=x(7,:);
x(7,:)=x(8,:);
x(8,:)=temp;
h=patch(x(5:8,1),x(5:8,2),x(5:8,3),c);
set(h,'FaceAlpha',alpha);
%WeltkoordinatenSystem
axis([0,10,0,10,0,10])
xlabel('X-Achse')
ylabel('Y-Achse')
zlabel('Z-Achse')
grid on
hold off
end;
end
You do not need to put the m-file in your Matlab fcn block, you have just to call the function in the block Matlab fcn. but you need to use i,d,c,alpha as constants or signals
function y = load_handles(i,d,c,alpha)
%#codegen
y = test_environment(i,d,c,alpha)

La pregunta está cerrada.

Etiquetas

Preguntada:

sia
el 3 de Jun. de 2013

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by