how to connect two functons in matlab

I am want to connect two functions: In first function(firstf.m),i want to make a 'for' loop to variables p,r then I calculat [s] for each value then i use this value in second function accuracy that should repeat 100 time The first function is
[s] = firstf(data,k,opts)
p = 30;
if isfield(opts,'p')
p = opts.p;
end
for r = 20:22;
if isfield(opts,'r')
r = opts.r;
.
.
.
.
[s] = k_means(U,k)
first how to make for loop for variables p,r in first function and take every [s] (output of first function ) to calculate accuracy (second function) that should repeat 100 times

9 Comments

muhammad - are opts.p and opts.r arrays? Do you expect to iterate over these arrays to get the individual elements that you will use to compute the s which you will then pass to the second function 100 times?
It isn't clear (from the above) why you start to iterate over 20,21,22 using the indexing variable of r which you then override with opts.r. Please provide more details and the signature of your second function and describe how it is to be used. I understand that we provide s to this function and that it must return something (the accuracy) but then do you feed that accuracy back into the second function?
the first code
[s] = firstf(data,k,opts)
p = 30;
r = 20;
.
[s]=k_means(U,k)
and the second function
Accuracy=ya(data,x)
.
.
[s] = firstf(adj,x)
.
A = s(linindices);
Accuracy = mean(auc)
i want to variables p and r to take range of values and in each time calculate s using first function then calculate accuracy using second function then return to first function to take next values to variable p ,r and calculate s and so on.
Geoff Hayes
Geoff Hayes on 17 Apr 2016
Edited: Geoff Hayes on 17 Apr 2016
But why is p 30 and r 20? How do you intend to make a 'for' loop to variables p,r as you stated in your question? It isn't clear to me how p and r change over time or iterations. Do you obtain p and r from arrays or from something else?
As for the second function, why does it call the first function? I thought that you wanted to pass the s from the first function into the second function.
p=30 and r=20 is random i want to p=1:100 and r=1:100
to obtain the better s and calculate better accuracy
It sounds like you may have two loops here
for p=1:100
for r=1:100
% do something to calculate s
% refine s
end
end
Is the above correct? Also, please answer my second question as to why the second function calls the first one.
but in previous code i obtain on only final value of s so when i transfer to second function (another program) i obtain on only value of accuracy
in above code how to obtain all values of s (saved)
the above code not required but the second function calls the first to calculate accuracy that its calculation depend on the value of s
@muhammad: I still do not understand, what you want to achieve.

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 16 Apr 2016

Commented:

Jan
on 17 Apr 2016

Community Treasure Hunt

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

Start Hunting!