Đang chuẩn bị liên kết để tải về tài liệu:
Lecture 4: Input and output

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

To print a variable in your display on the command window, its place must be indicted by % in the format-string followed by the format of presentation (d, f, e, g). %d: integer notation %f: fixed point (decimal) notation %e: exponential notation %g: whichever is shorter, %f or %e | Lecture 4 Input and Output input fprintf © 2007 Daniel Valentine. All rights reserved. Published by Elsevier. Input Some options: Assign values to variables in a command line using the equal ( = ) sign. Use the input function for interactive assignment of values to some of the variables within your computer program. Input function General format: The display in the Command window: Type a value after the displayed prompt; the variable now has been assigned the value that was entered. variable = input('Please enter a value: ') Please enter a value: Area of a circle: Type this into an m-file: Execute and see this display in Command Window: Hands on Please enter the radius: 5.2 radius = 5.2000 area = 84.9487 Hands on Free falling object: Type this into an m-file: Execute: See this display in Command Window: Please enter the initial height (in meters): 25 Please enter the time the object was in the air (in seconds): 3 Please enter the initial velocity (in meters): 5 height_f = 84.1450 Input strings of text General format: The display in the Command window: This is used when the input is a string (e.g., names, months, etc.). The variable, in this case, is a ‘char’ class (or type). string = input('Please enter your name: ', 's') Please enter your name: The display variables: You can display the value of a variable in different ways. Typing “variable =” in the command window Using the fprintf command: Type into an m-file: Executing it displays in the Command Window: Output options x = 500 The value of x is 500. fprintf() The fprintf() command is one way to display the value of a variable with a label. General format: MATLAB code: fprintf('format-string', variable) Note: You can also use the disp() function to display results. See the help on disp() and the examples in the text. Placeholders in fprintf() To print a variable in your display on the command window, its place must be indicted by % in the format-string followed by the format of . | Lecture 4 Input and Output input fprintf © 2007 Daniel Valentine. All rights reserved. Published by Elsevier. Input Some options: Assign values to variables in a command line using the equal ( = ) sign. Use the input function for interactive assignment of values to some of the variables within your computer program. Input function General format: The display in the Command window: Type a value after the displayed prompt; the variable now has been assigned the value that was entered. variable = input('Please enter a value: ') Please enter a value: Area of a circle: Type this into an m-file: Execute and see this display in Command Window: Hands on Please enter the radius: 5.2 radius = 5.2000 area = 84.9487 Hands on Free falling object: Type this into an m-file: Execute: See this display in Command Window: Please enter the initial height (in meters): 25 Please enter the time the object was in the air (in seconds): 3 Please enter the initial velocity (in meters): 5 .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.