how to use a function in an other one?
1 view (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
Walter Roberson
on 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 Comments
See Also
Categories
Find more on Signal Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!