how to use a function in an other one?

1 次查看(过去 30 天)
hi everybody
so i have this function which calculates the energy of a given configuration(a matrix), the code is as:
function [ Uobj ] = dataterm( X,d0,image )
X=[271 122 15 13 90;244 165 14 12 85;157 126 16 13 70;36 63 17 15 92;280 199 16 11 30;45 229 14 10 90];
image='cour.png';
Uobj=0;
d0=20;
for i=1:size(X,1)
x=X(i,1);
y=X(i,2);
a=X(i,3);
b=X(i,4);
teta=X(i,5);
[ coord bord] = inellipse( x,y,a, b,teta,image );
.
.
.
i want to use this function in another function which is
function[d]=death(w)
beta=100;
lambda=10;
image='cour.png';
d0=20;
[u]= dataterm(w);
...
i want to use the dataterm function with others inputs in other function such birth(), but it returns always the same results which is the energy of the var X?? any help?

回答(1 个)

Walter Roberson
Walter Roberson 2016-1-22
You overwrite all of your inputs with constant parameters, so no matter what is passed in, you always do the same thing. You should generally only assign to the parameters if you detect that the parameter is missing.
Your call to dataterm() should be passing in all three parameters.
You do not happen to show the code for inellipse(). You should be sure to check whether it takes an image data array (as most routines do), or if it takes an image file name (which is what you are passing in.)
Note: you should never name a variable "image" as that interferes with using the image() graphics routine.
  2 个评论
amal Mbarki
amal Mbarki 2016-1-22
编辑:amal Mbarki 2016-1-22
thank you,i am still debutant so my question may be banal,how to make parameter non constants?? for example the X parameters in dataterm() but in the same time in need a structure to work with within the function??
amal Mbarki
amal Mbarki 2016-1-22
ohhh it's ok, i get it now .thanks alot

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Signal Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by