Write a function fml(x) where given vector x returns first, middle and last. If the number of elements in the vector are even, middle should take the mean value of the innermost elements.
Mostra commenti meno recenti
function [first, middle, last] = fml(x)
%FML Returns the first, middle, and last element of x
first = x(1);
last = x(length(x));
middle = x(length(x))/2;
if mod(length(x),2)==1
middle = (x(length(x)/2+1)+x(length(x)/2-1))/2;
elseif mod(length(x),2)==0
middle = x(length(x))/2;
end
--------- It is not working for some reason. Getting errors at the IF sequence.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Communications Toolbox in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!