matlab - dynamically specifying floating point number size in a function-enclosed sscanf statement -


I have a structured data file that contains header lines with block of data. I Line defined) in a separate cell of the cell array. For example, suppose that after loading data with textscan , I have a cell array x and header lines and EOF ( headerIdx The following form:

  x = {'header line 1'; '98 .78743 '; '99.399717 '; '99.997878 '; '100.40125'; '100.79166'; '101.10525'; '101.34037'; 101.49 553; '101.56 9 3'; '101.56072'; '101.4685'; '101.2 9 184'; '101.03002'; '100.68249'; Header line 2 ';' 100.24887 ';' 99.72897 ';' 99.12274 '; '98.443036 ';' 97.65215 ';' 96.78864 ';' 95.84054 ',' Header Line 3 ';' 3.2 ';' 4.31 ';' 2.7 ';' 4.6 ';' 9.3 '}; HeaderIdx = [1; 16; 24; 30];  

Then I have a different element of a cell array by using sscanf and str2mat each block of data below a header line I try to remove (as suggested) in the beginning, this approach failed, because the elements in a given block of data were of different lengths. It can be solved by adding a numeric flag for the '% f' argument to help sscanf , where input data (as suggested) To be demarcated One can again use a strategy, such that to convert the structured data into a block-specific double array of cell array:

  extract_data = @ (n) sscanf (str2mat) (X (HeaderIDX (N) +1: Headerindex (N + 1) -1 ',' ['%' number 2:25 (size (strobeat (x (headerindex (n) +1: header-index (n + 1 ););  

format string The numerical flag of either To encircle the set, some can be set to scale, or set on a block-specific basis as I have done in the example above. Redemption goes to evaluation (once for input in sscanf and once for the input of 'code' 'string' string generator) Do this redundant save without loop statement? Which can be done by typing str2mat in a floating variable Output to the store? Note that any Size command can not use str2mat (x) production. ' is set on the entire data set because the header lines are usually going to line up with the largest number of characters.

Finally, I have created the above given code to reflect the fact that some blocks of data can be different in comparison to other blocks. This is the reason to set the format string in a block-specific manner. My test has been shown that the block-specific format string ( ['%' num2str (the exact size of str2mat (x (header idx +1): headerindex (n + 1) -1)) Despite the creation. 'F'] ), the data is eventually forced to do the same exact (see below) all elements of the cell array ( extracted_data ) Why is it, and how can it be corrected?

  extracted_data {:} ans = 98.7874 99.3 9 72 99.9358 100.4013 100.7917 101.1052 101.3404 101.4955 101.5694 101.5607 101.4685 101.2918 101.0300 100.6825 Answer = 100.248 99.7290 99.1227 98.4304 97.6522 96.7886 95.8405 ans = 3.2000 4.3100 2.7000 4.6000 9.3000 < / Code> 


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -