2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
When the amount of Excel data is huge, manual data processing will become a thankless task, which is prone to errors and depression.
Using Matlab to process becomes a simple and efficient way.
For example, taking the pin reuse table of the GD32F7xx series as an example, in the 169x19 Excel table:
How to quickly get all corresponding pins and AF values of UART7_RX and output the information in array form.
xlsread It is a mathematical softwarematlabReadExcelA function that reads the data in the file. That is, read the file from the cell in the folder where the current program is located according to the range specified by the function parameter and returns the data.
(1)num = xlsread(‘filename’)
Read from a specified folder, for examplenum=xlsread(‘data.xls’),That is, from the folder where the current program is located, fromA1The cell starts reading, readingdata.xlsfile, return the data tonum。
(2)num = xlsread(‘filename’,‘sheet’)
Select thesheet, for example’sheet1’。
(3)num = xlsread(‘filename’, ‘range’)
The cell range, for examplerange=‘A1:A8’。
(4)num = xlsread(‘filename’, ‘sheet’, ‘range’)
sheetand cell range at the same time.
(5)[num, txt]= xlsread(‘filename’, …)
Save the returned data separately from the text.
(6)[num, txt, raw] = xlsread(‘filename’, …)
Separately save, there isnumandtxtSave toraw, forming a single variable.
in,numis a numeric variable and a matrix,txtis a character variable and a cell array,rawContains both numeric variables and character variables.rawis a cell array.
1.strcmp(s1, s2): used to compare whether the strings s1 and s2 are equal. If they are equal, it returns the result 1, otherwise it returns 0;
For example:
TF=strcmp(s1,s2);
s1 and s2 are strings, for example: s1='hello', s2='matlab'.
If s1 and s2 are consistent, the return value TF=1, otherwise, TF=0.
TF=strcmp(s,c);
s is a string, c is a cell array, and all elements of c are strings, for example: s='hello', c={'hello','matlab';'HELLO','matlab'}.
The return value TF is an array with the same length as c, and the elements of TF are 1 or 0.
Compare each element in c with s. If they are the same, the element at the corresponding position of TF is 1, otherwise, it is 0.
TF=strcmp(c1,c2);
c1 and c2 are both cell arrays, and they have the same length, and their elements are all strings, such as c1={'hello','matlab';'HELLO','matlab'}; c2={'hello','matlab';'hello','MATLAB'};
The return value TF is a logical array with the same length as c1 or c2, and the elements of TF are 1 or 0.
Compare the elements at corresponding positions of c1 and c2. If they are the same, the element at the corresponding position of TF is 1, otherwise, it is 0.
2.strncmp(s1, s2, n): used to compare whether the first n characters of strings s1 and s2 are equal. If they are equal, it returns the result 1, otherwise it returns 0;
3.strcmpi(s1, s2): Compares the strings s1 and s2 to see if they are equal, ignoring the case of the letters. If they are equal, it returns 1, otherwise it returns 0;
4.strncmpi(s1, s2, n): Compares the first n characters of strings s1 and s2 to see if they are equal, ignoring the case of the letters. If they are equal, returns 1, otherwise returns 0.
1. Define the output array, extract the excel file content and generate a txt array:
- >> OUTPUT=cell(10,2);
-
- >> [~,txt] = xlsread('D:aaabbbccc.xlsx');
Now you can see the variables:
2. Edit the conversion function:
Traverse all the contents and compare them, find all the corresponding pins and AF values of UART7_RX, and output the information in array form.
- function OUTPUT=excel_read(specified_txt)
- [~,txt] = xlsread('D:aaabbbccc.xlsx');
- m = 1;
- OUTPUT=cell(10,2);
-
- for i=1:169
- for j=1:19
- if strcmp(txt(i,j),specified_txt)
- OUTPUT(m,1)=txt(i,1);
- OUTPUT(m,2)=txt(1,j);
- m=m+1;
- end
- end
- end
- end
3. Calling the function:
>> OUTPUT=excel_read('UART7_RX')
The following results can be obtained:
That is: all corresponding pins and AF values of UART7_RX, and output the information in array form.