Assuming that x
is a row vector, we can use MATLAB's indexing and sum functions to compute the scalar r
as follows:
main.m111 chars3 lines
Here, we are using x(1:20)
to extract the first 20 elements of x
, x(end-4:end)
to extract the last 5 elements of x
, and sum()
to compute the sum of each sub-vector. Finally, we add the two sums to obtain the scalar r
.
gistlibby LogSnag