how to connect two functons in matlab
Mostra commenti meno recenti
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 Commenti
Geoff Hayes
il 16 Apr 2016
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?
muhammad ismat
il 16 Apr 2016
Modificato: Geoff Hayes
il 17 Apr 2016
Geoff Hayes
il 17 Apr 2016
Modificato: Geoff Hayes
il 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.
muhammad ismat
il 17 Apr 2016
Modificato: muhammad ismat
il 17 Apr 2016
Geoff Hayes
il 17 Apr 2016
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.
muhammad ismat
il 17 Apr 2016
muhammad ismat
il 17 Apr 2016
muhammad ismat
il 17 Apr 2016
Jan
il 17 Apr 2016
@muhammad: I still do not understand, what you want to achieve.
Risposte (0)
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!