Function keeps running into errors when I call it
1 回表示 (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
Star Strider
2021 年 10 月 17 日
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 件のコメント
その他の回答 (0 件)
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!