write a loop sums the values of those elements of “x” that are lower than 26. in matlab

Here's one way to write a loop in Matlab that sums the values of elements in an array x that are lower than 26.

main.m
x = [10, 20, 30, 40, 12, 24, 8, 50];
total = 0;
for i = 1:length(x)
    if x(i) < 26
        total = total + x(i);
    end
end
disp(total);
140 chars
9 lines

In this code, we define an array x and initialize a variable total to 0. We then loop through each element in x, and check if it is less than 26. If it is, we add it to the total variable. After the loop is finished, we display the total value using the disp function.

You can replace the example x array with your own array as needed.

gistlibby LogSnag