How to read csv files in matlab: first open the "matlab" software on the computer and find the csv file on the computer; then enter the code in the command line window at the arrow, the command is [csvread()]; finally In brackets is [the directory file name of the csv file].
The operating environment of this article: Windows 7 system, matlab r2016b version, Dell G3 computer.
How matlab reads csv files:
1. First open the "matlab" software on the computer. The main interface is as shown below, with the command line window at the arrow. Enter the code to run.
#2. Next, find the csv file on the computer, as shown in the figure below. The name of the csv file is data.csv.
3. The command for matlab to read csv files is csvread(), and the directory file name of the csv file is in brackets. The storage directory of data.csv is C:\Users\50123\Desktop\data.csv. The directory of each file is different, just check the properties of the file.
4. If you need to output specific rows and columns of the csv file, use a=csvread(filename,1,2) to output the second to fourth lines of the file. From the third column to the fourth column, the output result is as shown in the figure below. When matlab reads the csv file, 0 is used as the first row and first column.
5. Use the command a=csvread(filename,1,0,[1,0,2,3]) to output the second to third lines of the file , the first to fourth columns, the output results are shown in the figure below.
#6. If the file is all data, you can drag the file to the matlab workspace. The system pop-up window will appear as shown below. You can see the file at the arrow. The data.
#7. Select the data to be exported and select the type of imported data in "Imported Data". You can export it as a column vector or numerical matrix. Click the arrow "Import selected content" to export the data.
#8. Next, you can see the exported data in the matlab workspace, as shown in the figure below.
If you want to learn more about programming, please pay attention to php trainingcolumn!
The above is the detailed content of How matlab reads csv files. For more information, please follow other related articles on the PHP Chinese website!