How to create a matlab function?

1 view (last 30 days)
Tessa on 12 Jan 2017
Commented: Image Analyst on 16 Jan 2017
Hi, I'm trying to create my own matlab function, but I don't really understand the way it works;
Here is what I have:
function [Y] = CalibratieABP(ABP)
%UNTITLED5 Summary of this function goes here
% Detailed explanation goes here
afstand = 4; %over hoe lang je het gemiddelde neemt
k = 4; %onder en bovengrens
lengte=25; %lengte hoelang achter elkaar +- 0
p = ABP; %ABP of CVP? ook aanpassen in titel
% gemiddelde stukje nemen
mean = movmean(p,afstand);
Y1 = mean<k;
Y2 = mean>-k;
Yy = Y1.*Y2;
%minimaal aantal opeenvolgende 1
Y = zeros(size(p));
locations = strfind([Yy'], ones(1,lengte));
for i=1:lengte
Y([locations+i-1]) = 1;
the %adds some extra information.
I know that i'm doing something something wrong with the function at the beginning, but I don't see what it should be like.
I want ABP as input and Y as output.

Answers (1)

Wilson A N
Wilson A N on 16 Jan 2017
The format in your script is correct for ABP as input and Y as output. Also, when creating your own MATLAB function you need to save the function .m file with the same name as the function. In your case the function .m file should be named as 'CalibratieABP.m'. For more information just check the documentation given below:
I tried the above script and called the MATLAB function as
>> a = Calibratie(10);
from the MATLAB command line. This is working for me.
Image Analyst
Image Analyst on 16 Jan 2017
Maybe she's not calling it and passing it data. Maybe she's just hitting F5 or clicking the green run triangle. Who knows? Only Tessa, because she didn't tell us what the problem was, like pasting ALL the red text from an error message, or giving us the output data and saying why it's not right, or something.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by