how to use a function in an other one?

1 vue (au cours des 30 derniers jours)
amal Mbarki
amal Mbarki le 22 Jan 2016
Commenté : amal Mbarki le 22 Jan 2016
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?

Réponses (1)

Walter Roberson
Walter Roberson le 22 Jan 2016
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 commentaires
amal Mbarki
amal Mbarki le 22 Jan 2016
Modifié(e) : amal Mbarki le 22 Jan 2016
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 le 22 Jan 2016
ohhh it's ok, i get it now .thanks alot

Connectez-vous pour commenter.

Catégories

En savoir plus sur Signal Processing Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by