Lecture 2 MATLAB fundamentals

Variables, Naming Rules, Arrays (numbers, scalars, vectors, matrices), Arithmetical Operations, Defining and manipulating arrays Variables What are variables? You name the variables (as the programmer) and assign them numerical values. | Lecture 2 MATLAB fundamentals Variables, Naming Rules, Arrays (numbers, scalars, vectors, matrices), Arithmetical Operations, Defining and manipulating arrays © 2007 Daniel Valentine. All rights reserved. Published by Elsevier. Variables What are variables? You name the variables (as the programmer) and assign them numerical values. Variable Naming Rules Must begin with a LETTER May only contain letters, numbers and underscores ( _ ) No spaces or punctuation marks allowed! Only the first 63 characters are significant; beyond that the names are truncated. Case sensitive (. the variables a and A are not the same) Which variable names are valid? 12oclockRock tertiarySector blue cows Eiffel65 red_bananas This_Variable_Name_Is_Quite_Possibly_Too_Long_To_Be_Considered_Good_Practice_However_It_Will_Work % (the green part is not part of the recognized name) Variable Naming Conventions There are different ways to name variables. The following illustrate some of the conventions used: lowerCamelCase UpperCamelCase underscore_convention If a variable is a constant, some programmers use all caps: CONSTANT It does not matter which convention you choose to work with; it is up to you. In MATLAB, a variable is stored as an array of numbers. When appropriate, it is interpreted as a scalar, vector or matrix. The size of an array is specified by the number of rows and the number of columns in the array, with the number of rows indicated first. Variables as Arrays scalar 1 × 1 vector n × 1 or 1 × n matrix n × m Scalars are 1×1 arrays. They contain a single value, for example: Scalars Vectors A vector is a list of numbers expressed as a 1 dimensional array. A vector can be n×1 or 1×n. Columns are separated by commas (or spaces): Rows are separated by semicolons: Matrices A matrix is a two dimensional array of numbers. For example, this is a 4×3 matrix: 1 2 3 1 2 3 4 Columns Rows Indexed-location | Lecture 2 MATLAB fundamentals Variables, Naming Rules, Arrays (numbers, scalars, vectors, matrices), Arithmetical Operations, Defining and manipulating arrays © 2007 Daniel Valentine. All rights reserved. Published by Elsevier. Variables What are variables? You name the variables (as the programmer) and assign them numerical values. Variable Naming Rules Must begin with a LETTER May only contain letters, numbers and underscores ( _ ) No spaces or punctuation marks allowed! Only the first 63 characters are significant; beyond that the names are truncated. Case sensitive (. the variables a and A are not the same) Which variable names are valid? 12oclockRock tertiarySector blue cows Eiffel65 red_bananas This_Variable_Name_Is_Quite_Possibly_Too_Long_To_Be_Considered_Good_Practice_However_It_Will_Work % (the green part is not part of the recognized name) Variable Naming Conventions There are different ways to name variables. The following illustrate some of the .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.