find the summation of numbers greater than 5 only from 1 to 10 using for loop. in matlab

To find the summation of numbers greater than 5 only from 1 to 10 using a for loop in MATLAB, you can follow these steps:

  1. Initialize a variable to store the summation.
  2. Use a for loop to iterate over the numbers from 1 to 10.
  3. Inside the for loop, check if the current number is greater than 5.
  4. If the number is greater than 5, add it to the summation variable.
  5. Finally, display the summation.

Here's the MATLAB code to accomplish this:

main.m
summation = 0;
for number = 1:10
    if number > 5
        summation = summation + number;
    end
end

disp(summation);
121 chars
9 lines

Running this code will display the summation of numbers greater than 5 from 1 to 10, which in this case is 30.

related categories

gistlibby LogSnag