matlab exercise program (read column data inconsistency)

Normally we use matlab loading data, or use load importdata basic function will be able to meet the demand.

However, if the data column is inconsistent, do not want the time to read each line of data to traverse, you can use this function textscan.

For example, the following piece of data:

1 2 3

2 3 5 6

4 5 6 7 8

1 3 7 9 2 

It may be treated with the following code:

All Clear; 
Close All; 
CLC; 

FP = the fopen ( ' test.txt ' , ' R & lt ' ); 
textcell = textscan (FP, ' % F% F% F% F% F ' , ' DELIMITER ' , '  ' ); % formatted by most column, a space is divided 
data = cell2mat (textcell);% turn in a matrix form, and then the data is valid can be determined by Nan 
fclose (fp);

Data obtained to facilitate subsequent processing of the data.

Guess you like

Origin www.cnblogs.com/tiandsp/p/11295324.html