how to use a function in an other one?

조회 수: 1 (최근 30일)
amal Mbarki
amal Mbarki 2016년 1월 22일
댓글: amal Mbarki 2016년 1월 22일
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