Importing a signed integer value with a space

1 回表示 (過去 30 日間)
Sander Bovee
Sander Bovee 2020 年 8 月 12 日
コメント済み: hosein Javan 2020 年 8 月 12 日
Hello everyone,
I have a data file, i'm trying to import into MATLAB. Several columns are signed integers (see example below):
'+ 24.05' '+ 2.429' '+ 1.460' '+ 2.236'
'+ 24.05' '+ 2.429' '+ 1.459' '+ 2.237'
'+ 24.05' '+ 2.429' '+ 1.462' '+ 2.235'
I'm using the datastore function and then modifying the SelectedFormats setting to adjust to the format to correctly import the data.
I'm trying to use the signed integer values format ('%d') to import this data, however it does not reconize the values above as such. I believe its due the space between the sign and the integer.
Is there a Optional operator(s) that i can add to ignore the space? Or am i perhaps wrong in my assumption that the space is the issue?

採用された回答

hosein Javan
hosein Javan 2020 年 8 月 12 日
if your data are all positive, then you can ignore plus sign. and your data is not integer use single or double precion. here's a code that imports the data from a text file to matrix.
fileid = fopen('scan1.txt')
c = textscan(fileid,'''+ %f'' ''+ %f'' ''+ %f'' ''+ %f''')
c = cell2mat(c)
c =
24.0500 2.4290 1.4600 2.2360
24.0500 2.4290 1.4590 2.2370
24.0500 2.4290 1.4620 2.2350
  4 件のコメント
Sander Bovee
Sander Bovee 2020 年 8 月 12 日
Thanks! I've just imported it has a character vector and used your cellfun to converted it to doubles.
That works and is a whole lot less complicated that my previous IF statement solution. Thank you both!
hosein Javan
hosein Javan 2020 年 8 月 12 日
don't mention it. you can even store the matrix data in a .mat file afterwards so you won't need to convert string to number every call of your script or function.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by