Arrays
()
instead of []
myPeaks
:
myPeaks(1)
myPeaks[0]
For loops
for j = 1:4
for (int j = 0; j < 4; j++)
Checking for not equals
a ~= b
a != b
Instead of brackets for if
, while
, and for
loops, etc. , MATLAB uses end
MATLAB:
if (a > b)
% do something
end
C++:
if (a > b){
// do something
}
Functions in MATLAB have slightly different formatting, and don’t require variable types
MATLAB:
function heartRate = ihr(t1, t2)
heartRate = 1/(t2 - t1)*60;
end
C++
float heartRate(float t1, float t2){
return 1/(t2 - t1)*60;
}
In MATLAB, use elseif
instead of else if
in C++
MATLAB:
if (a > b)
% do something
elseif (b > a)
% do something else
else
% do yet another thing
end
C++
if (a > b) {
// do something
}
else if (b > a) {
// do something else
}
else {
// do yet another thing
}
hold on
and hold off
control whether new plots are added to an existing figure or the figure is overwritten%
;
IHR = ihr(t1, t2)
will print IHR