Function keeps running into errors when I call it

6 visualizzazioni (ultimi 30 giorni)
Hello,
I am running into errors when I try and call my function below by using
[phivalues] = findphases(wpeakt,hpeakt)
%Function below
function [phivalues] = findphases(wpeakt,hpeakt)
newhpeaks = [ ];
phivalues = [ ];
hpeakt = sorteddata.data(:,1);
wpeakt = sorteddata.data(:,5);
for i=1:length(wpeakt)-1;
tau=wpeakt(i+1)-wpeakt(1);
newhpeaks = hpeakt(find(wpeakt(i)<hpeakt<wpeakt(i+1))); %finds haltere value between Tau wing peaks
newhpeaks = newhpeaks(1); %finds "first" neural spike
deltat=newhpeaks-wpeakt(i);
phi=2*pi*(deltat/tau);
phivalues = [phivalues phi];
end
plot(wpeakt,ones(size(wpeakt)),'bo');% ones is y axis
hold on
plot(hpeakt,ones(size(hpeakt)),'ro');
end
The data is being imported as a 1x1 struct, which is why hpeakt and wpeakt are sorteddata.data. hpeakt is all of column 1, and wpeakt is all of column 5. When I call the function I get the error "Unrecognized function or variable 'wpeakt'." When I highlight the entire function script without the function line it comes up fine with my graph and everything. I'm not sure why I am running into issues calling it though. I have my function file named "findphases."
I am also getting the error
>> [phivalues] = findphases(wpeakt,hpeakt)
Unable to resolve the name sorteddata.data.
Error in findphases (line 5)
hpeakt = sorteddata.data(:,1);
Any help is appreciated.

Risposta accettata

Star Strider
Star Strider il 17 Ott 2021
Try this instead —
hpeakt = sorteddata.data(:,1);
wpeakt = sorteddata.data(:,5);
[phivalues] = findphases(wpeakt,hpeakt)
function [phivalues] = findphases(wpeakt,hpeakt)
newhpeaks = [ ];
phivalues = [ ];
for i=1:length(wpeakt)-1;
tau=wpeakt(i+1)-wpeakt(1);
newhpeaks = hpeakt(find(wpeakt(i)<hpeakt<wpeakt(i+1))); %finds haltere value between Tau wing peaks
newhpeaks = newhpeaks(1); %finds "first" neural spike
deltat=newhpeaks-wpeakt(i);
phi=2*pi*(deltat/tau);
phivalues = [phivalues phi];
end
plot(wpeakt,ones(size(wpeakt)),'bo');% ones is y axis
hold on
plot(hpeakt,ones(size(hpeakt)),'ro');
end
I obviously cannot test this, so I leave that to you.
Define the variables first, then pass them to the function.
Also, the first plot will be a horizontal line at 1 going from ‘min(wpeakt)’ to ‘max(wpeakt)’. The second will be similar. Is that what you want?
.
  2 Commenti
Kristin Aldridge
Kristin Aldridge il 17 Ott 2021
It worked! Thank you. Yes the plot is a horizontal line because the peaks are "in phase" so that is correct.
Star Strider
Star Strider il 17 Ott 2021
As always, my pleasure!
(I just wanted to be sure about the plots.)
.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Deep Learning Toolbox in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by