MATLAB loop structure: While statement p69 norm to be compiled

Source: Internet
Author: User
  1. The general format of the while statement is:
While condition loop body statement end
  1. Enter several numbers from the keyboard. When the input is 0, end the input and calculate the average value of these numbers and their sum.

The procedure is as follows:

Sum = 0; n = 0; X = input ('enter a number (end in 0): '); While X ~ = 0 sum = sum + X; n = n + 1; X = input ('enter a number (end in 0): '); endif (n> 0) summean = sum/nend

Output:

Enter a number (end in 0): 555656
Input a number (end in 0): 2
Input a number (end in 0): 2
Input a number (end in 0): 2
Enter a number (end in 0): 20
Input a number (end in 0): 0

 

Sum =

 

555682

 


Mean =

 

1.1114e + 005

 
  1. Calculate the matrix index based on the idempotence expansion of the matrix Index

MATLAB loop structure: While statement p69 norm to be compiled

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.