Matlab processing csv file and graph drawing summary

Recently, experiments need to use matlab to import and process csv file data. Before that, I was not familiar with the use of matlab, so I took the opportunity of writing a blog to summarize and consolidate.
1. Script program clear command:
clc: clear the content of the command line window, it has no effect on the content of the editor and the workspace.
Enter clc in the command line window and press Enterclose and close all: the two functions are the same, the former is to close the current Figure window; the latter is to close all Figure windows.
Clear and clear all: the two functions are similar, the former is to clear all variables in the workspace; the latter is to clear all variables , Functions and running files, etc.
Use clear to clear the variables here
Generally, before writing a script program, use the clc, clear all, close all commands to completely reset the program before running.

2. File import processing:
Matlab has a wealth of file import functions, such as load, importdata, save, textscan, read functions, etc., here is a summary of the usage of
importdata function : importdata function can be from txt, csv, excel and picture files Import data, its commonly used forms are as follows:

data = importdata(filename);
data = importdata(filename, delimiter);
data = importdata(filename, delimiter, headerlinesIn );

Among them, data is used to store the read file data, the importdata function imports the data into a structure variable, and the text and numbers are respectively imported into attributes with different structures: the value is imported into the matrix, and the text is imported into the cell array. filename is the file name, delimiterIn is the character delimiter; headerlinesIn is the number of lines in the file header.
The importdata function is summarized as above
3. File data search and match:
matlab provides three regular expression functions:

Regexp function: used to find strings, case sensitive;
regexpi function: used to find strings, case insensitive;
regexprep function: used to find and replace strings

The commonly used function forms are as follows:

regexp(str,expression,'match'); Matches from the str string and returns the expression string, which is case sensitive.
regexp(str,expression,'split'); split the str string according to the expression expression form
regexpi(str,expression,'match'); match from the str string and return the expression expression string, not case sensitive write.
regexprep(str,expression1,expression2); Replace the expression1 expression in the str string with expression2.

Example:
tmp=regexp(str,',' ,'split'); %Regular expression, split the str string by',', and the result is stored in tmp
regexp(str,'abc','match')) ; %Start from str to match the expression that matches abc
regexprep(str,'abc','a')); %Replace the'abc' character in str with a

Note:.
Means to match any single character (except newline character \n), * means greedy mode. For example, a.*b, it will match the longest string that starts with a and ends with b. If you use it to search for the string "aabab", it will match the entire string aabab. This is called greedy matching.

4. Graph drawing:
There are rich and powerful graph drawing functions in matlab. Among them, the most widely used is the plot function. The common forms of the plot function are plot(X), plot(X,Y), plot(X,Y,... ), where XY is a vector of the same length, which stores the X-axis and Y-axis coordinates of the Figure respectively. Various drawing attributes can be added to the plot function, such as:

LineWidth-specify the line width
MarkerEdgeColor-specify the edge color of the
identifier MarkerFaceColor-specify the fill color of the
identifier MarkerSize-specify the size of the identifier

Note that the above four attributes are for all curves in the current coordinate system. The line type attributes in the drawing are as follows:
Line type attributes
other graphic settings such as:

title('Figure name'); Add title
text(x,y,'graphic description') to the graph; Add description
xlabel('x-axis description');
ylabel('y-axis description') in the specified x and y coordinates ;
axis on/off; display/cancel
axis equal; the increments of each tick mark on the xy axis are the same
grid on/off turn on/off the axis grid lines

Example:

point_X=[x1,X_aim,x2]; 		%point_X=[0, 62.71, 100]
point_Y=[y1,Y_aim,y2];		%point_Y=[0, 16.80, 0]
plot(point_X, point_Y, ':^r', 'markersize',8);		%点线,上三角标记,红色,标记大小8
title('这是一张figure图');		%标题
xlabel('x轴坐标');		%轴加备注
ylabel('y轴坐标');
text(X_aim+2,Y_aim+1,'1');		%指定坐标加备注
text(x1+2,y1,'2');
text(x2-4,y2,'3');
axis equal		%xy轴上的各个刻度线的增量相同
grid on		%坐标轴加网格线

Example

Guess you like

Origin blog.csdn.net/qq_42691315/article/details/112980255