Matlab 👩‍💻 File and User Input

APMonitor.com
APMonitor.com
1.7 هزار بار بازدید - 4 سال پیش - Input requests information from the
Input requests information from the person using the computer and pauses the program until a value is entered. Input can also be data from a file. This module shows how to access input data from either a user or a file.

For the final project egg incubator controller, certain types of eggs may require a different input and you could put that in your code to change the desired temperature. You could also use input to manually change power to the heaters.

If you run the code below, it asks you for a number. If they enter a number with a decimal or as a string, you need to turn eggs double into an integer with the function round() or int32(). Use these functions to change types. You can also make the input change into an integer on the same line as the input.

You can save data to a file with save -ascii filename data to save the input number to a file number.txt. The -ascii flag tells the computer to save the file in a human-readable form as a text file instead of a binary file. A binary file takes up less storage space and is faster to write and read by the computer but it is harder to inspect the file contents by another program. Use the flag -append to add to the end of the file instead of replacing the contents.


Data files on your computer such as a Comma Separated Value (CSV) file or a regular text file can also be an input to your program. There is more information on importing and analyzing data files. To load a file, use the load command followed by the file name. This loads the contents of number.txt back into Matlab as a variable name that does not include the file extension (.txt). In this case, the variable number is updated.


👩‍💻 Course Overview: https://apmonitor.github.io/begin_mat...
👩‍💻 Source Files on GitHub: https://github.com/APMonitor/begin_ma...
👩‍💻 TCLab: https://apmonitor.com/heat.htm
👩‍💻 Additional Online Courses: https://apmonitor.com/che263/index.ph...
4 سال پیش در تاریخ 1399/04/18 منتشر شده است.
1,712 بـار بازدید شده
... بیشتر