m files as Function Inputs !!
Afficher commentaires plus anciens
Dear all, I have several files with real data representing signals and in each file I draw the kernel estimate function for the data. I have another m file to calculate the delay so I want the two parameters for the delay function to be any signal from the files I created so when I runi it using the command I can choose any two signals and It will calculate the delay.. Not sure how to pass the two files as arguments.How can I in the xcorr argument say two different data?
function d = delayMethod(filename1,filename2)
data = importdata(filename);
[Rxx, lags] = xcorr(data, data);
[Y, delay] = max(Rxx);
lags(d)
end
Thanks, Susan
2 commentaires
Fangjun Jiang
le 19 Août 2011
Is your file a .m file or .mat file? Your title says .m file. Answers below assume .mat file.
If your file is .m file, then the variable name 'data' is dependent on the code inside the .m file.
Susan
le 19 Août 2011
Réponse acceptée
Plus de réponses (3)
Sean de Wolski
le 19 Août 2011
d = delayMethod('file1.mat','file2.mat');
calling something that uses the inputs:
function d = delayMethod(filename1,filename2)
data1 = importdata(filename1);
data2 = importdata(filename2);
[Rxx, lags] = xcorr(data1, data2);
[Y, delay] = max(Rxx);
lags(d)
end
1 commentaire
Susan
le 19 Août 2011
Paulo Silva
le 19 Août 2011
function d = delayMethod(filename1,filename2)
data1 = importdata(filename1);
data2 = importdata(filename2);
[Rxx, lags] = xcorr(data1, data2);
[Y, delay] = max(Rxx);
lags(d)
end
12 commentaires
Sean de Wolski
le 19 Août 2011
I like your naming convention!
Susan
le 19 Août 2011
Susan
le 19 Août 2011
Fangjun Jiang
le 19 Août 2011
What do you get if you run "clear all;work1"?
What do you get if you run "clear all;work2"?
Susan
le 19 Août 2011
Susan
le 19 Août 2011
Fangjun Jiang
le 19 Août 2011
All right! After you run work1.m, which variable are you going to use as the first input argument for delayMethod()? And which variable in work2.m are you going to use for the second argument? Is the variable name always the same for work3.m, work4.m ..., or is it different for every .m file?
Susan
le 19 Août 2011
Paulo Silva
le 19 Août 2011
@Sean de
I posted my answer about the same time as you and was funny to see it already there :)
Susan
le 19 Août 2011
Fangjun Jiang
le 19 Août 2011
Yeuk! You need to do it differently! It is poor programming but just get you through!
Sean de Wolski
le 19 Août 2011
Paulo, I know!
I posted mine, and when it returned yours was there, with identical recommendations. We've been brainwashed by the forum!
Susan
le 19 Août 2011
0 votes
1 commentaire
Fangjun Jiang
le 19 Août 2011
You really really need to go back to the basics of MATLAB. You don't have a clue of what you are doing after so many questions.
If you name the variable the same as "X" for work2.m and work3.m, then when you run delayMethod('work2','work3'), it is going to run work2 first, then run work3, the X variable is over-written. xcorr(X,X) is calculate the correlation of X itself from work3. If you switch the order, it is going to calculate the correlation of X itself from work2.
If you name the variable Y for work2 and X for work3, xcorr(Y,X) will be the same even if your switch the order delayMethod('work2','work3'), or delayMethod('work3','work2').
Catégories
En savoir plus sur Multirate Signal Processing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!