reading undelimited comma numbers

6 ビュー (過去 30 日間)
Philip
Philip 2014 年 11 月 5 日
編集済み: per isakson 2020 年 5 月 12 日
Apologise if this is an already resolved issue but I just cannot find the solution The lab. equipment spits out a .cti file which I try convert to .xlsx format I say try because I am unable to separate the comma delimited number so the rows looks like this:
-20.925926,119.3976
Any suggestion for an approach to read in the number, I have tried using
num = xlsread(filename,sheet,xlRange)
num = xlsread(filename,sheet,xlRange,'basic')
none worked - num returns as an empty array
I am thinking I should try to read in as a string extract the number as a string and convert to numerics
Thanks, Philip
  2 件のコメント
Image Analyst
Image Analyst 2014 年 11 月 5 日
Why do you say "undelimited" in the subject line? That row is delimited. What does "undelimited" mean to you?
per isakson
per isakson 2014 年 11 月 5 日
編集済み: per isakson 2014 年 11 月 5 日
Can you upload a sample file (paper-clip-button)? I understand that cti-file is a text file, but that's about all. Matlab Interface User’s Guide doesn't help.

サインインしてコメントする。

採用された回答

per isakson
per isakson 2014 年 11 月 5 日
Here is a file, which I think will extract the numerical data from your file. I tested with some data I found on the net.
Try
>> [ var_list, num ] = CITIFILE()
var_list =
1.0e+09 *
1.0000
2.0000
2.5000
3.0000
num =
[4x2 double] [4x2 double] [4x2 double]
where
function [ var_list, num ] = CITIFILE()
str = fileread( 'CITIFILE.txt' );
cac = regexp( str, '(?<=VAR_LIST_BEGIN).+?(?=VAR_LIST_END)', 'match' );
var_list = str2num( cac{1} );
cac = regexp( str, '(?<=\sBEGIN).+?(?=\sEND)', 'match' );
num = cell( 1, length(cac) );
for jj = 1 : length(cac)
str = strrep( cac{jj}, '"', '' );
num{jj} = str2num( str );
end
end
and &nbsp CITIFILE.txt &nbsp is copied from Agilent 8510 3-Term Frequency List Cal Set File and attached
  1 件のコメント
Philip
Philip 2014 年 11 月 5 日
編集済み: per isakson 2020 年 5 月 12 日
The routine is quite powerful and efficient, thanks.
Regards,
Philip

サインインしてコメントする。

その他の回答 (1 件)

Kelly Kearney
Kelly Kearney 2014 年 11 月 5 日
Trying to convert to an Excel format seems unnecessary and complicated... if you're planning to work with this data in Matlab only, I'd suggest skipping that step.
Can you show a few snippets of your file? In plain text. Are the comma-delimited portions of the file all one line, or are there a certain number of columns per row? Are all the data points in quoted pairs, or is that unique to line 16016?
  2 件のコメント
Philip
Philip 2014 年 11 月 5 日
編集済み: Philip 2014 年 11 月 5 日
Sure, the data file when open in note book looks like this
line 1 (in excel) to line 12 is text; looks like
CITIFILE A.01.01
"!Agilent Technologies,E8362B,MY43020295,A.06.03.05"
!Agilent E8362B: A.06.03.05
line 13 to line 16013 is data, no trouble reading these rows, looks like
10000000
10374375
10748750
2 lines of text at line 16014 and 5 then line 16016 on wards is shown below:
"-39.117367,-72.549469"
"-45.872181,76.079033"
"-46.924721,170.44943"
the qoutation marks shows up when the file is open using notepad
the first data line is missing using csvread and the first data value in the read is not read in, the read in data looks like
76.0790330000000
0
Thanks for the help this far,
Regards, Philip
Kelly Kearney
Kelly Kearney 2014 年 11 月 5 日
Okay, first off, this isn't a comma-delimited file... it's a text file with a few comma-delimited sections. So you're going to have to read it as such, parsing each section appropriately. A quick google search of the CITIFILE format suggests that the data portions of the file will be indicated by BEGIN and END keywords; is that the case in your file?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by