readcell関数​で取得するExcel​のデータ精度に関して

Excelのセルに「79.999999998」と反映し、値が「80」のように丸められたとします。
そのセル値をreadcell関数で取得したのですが、「79.999999998」ではなく「80」の値として取得されていることを確認しました。
readcell関数で、Excel内のセル値を取得する際に、丸められた値ではなく素の精度の値(今回の場合「79.999999998」)を取得できるようにするオプションはございますか?
■追記
readcell関数ではR2021aまでは、Excelデータの素の精度を取得することが出来ない。
その為、xlsreadを用いたり、readmatrixやreadtableなど、他の読込関数で読み込むほか回避する。
R2021bからは改善

6 Comments

Hernia Baby
Hernia Baby on 30 Sep 2021
確認ですが、これはどうしてもreadcellを使わなければいけないのでしょうか?
Hiroki Konno
Hiroki Konno on 30 Sep 2021
はい。
xlsreadでの取得では問題ないことはわかるのですが、それだとjenkinsとMATLABの連携の際に問題がでるので
問題が起こらないreadcellで取得したいと思い質問しました。
上記に従い、ファイルの内容に基づくインポート オプションを得て、"VariableTypes"が最初から"double"になっていたので、逆に80にするためにこれを"int8"に変えてreadcellを実行したのですが変わりませんね。何故ですか?
%opts = spreadsheetImportOptions % スプレッドシートのインポート オプション オブジェクト(1変数)のデフォルト値
opts = detectImportOptions('eighty.xls') % ファイルの内容に基づくインポート オプション
opts =
SpreadsheetImportOptions with properties: Sheet Properties: Sheet: '' Replacement Properties: MissingRule: 'fill' ImportErrorRule: 'fill' Variable Import Properties: Set types by name using setvartype VariableNames: {'Var1'} VariableTypes: {'double'} SelectedVariableNames: {'Var1'} VariableOptions: Show all 1 VariableOptions Access VariableOptions sub-properties using setvaropts/getvaropts VariableNamingRule: 'modify' Range Properties: DataRange: 'A2' (Start Cell) VariableNamesRange: '' RowNamesRange: '' VariableUnitsRange: '' VariableDescriptionsRange: '' To display a preview of the table, use preview
opts = setvartype(opts,{'Var1'},'int8') % 'Var1'の"VariableTypes"を'double'から'int8'に変更
opts =
SpreadsheetImportOptions with properties: Sheet Properties: Sheet: '' Replacement Properties: MissingRule: 'fill' ImportErrorRule: 'fill' Variable Import Properties: Set types by name using setvartype VariableNames: {'Var1'} VariableTypes: {'int8'} SelectedVariableNames: {'Var1'} VariableOptions: Show all 1 VariableOptions Access VariableOptions sub-properties using setvaropts/getvaropts VariableNamingRule: 'modify' Range Properties: DataRange: 'A2' (Start Cell) VariableNamesRange: '' RowNamesRange: '' VariableUnitsRange: '' VariableDescriptionsRange: '' To display a preview of the table, use preview
format long; readcell('eighty.xls',opts)
ans = 1×1 cell array
{[79.999999998000007]}
format short; readcell('eighty.xls',opts)
ans = 1×1 cell array
{[80.0000]}
format shortG; readcell('eighty.xls',opts)
ans = 1×1 cell array
{[80]}
Hiroki Konno
Hiroki Konno on 30 Sep 2021
Moved: Atsushi Ueno on 17 Aug 2022
ご回答ありがとうございます。
回答の内容を試してみたのですが、やはりうまくいきませんね、、、
また、cellの値も素の精度ではないですね。
「spreadsheetImportOptions」を利用することでcell配列で「79.999999998」の値を取得することができればいいのですが、、、
Hiroki Konno
Hiroki Konno on 4 Oct 2021
Moved: Atsushi Ueno on 17 Aug 2022
いろいろと対応して頂きありがとうございます。
あの後、私もいろいろと試してみたのですが、、
readcell関数では素の精度を取得することができませんでしたので、
xlsread関数を利用することにしました。
ご回答頂き感謝しています。
Hiroki Konno
Hiroki Konno on 5 Oct 2021
Moved: Atsushi Ueno on 17 Aug 2022
サポートに本件の内容を確認したところ
readcell関数ではR2021aまでは、Excelデータの素の精度を取得することが出来なかったようです。
その為、私が使用しているMATLABverはR2020bですので、Atsushi Uenoさんが対応してくだった内容が適用できなかったのもその影響によるものでした。
結論として、R2021aまではreadcell関数ではExcelデータの素の精度を取得することができないので、xlsreadを用いたり、readmatrixやreadtableなど、他の読込関数で読み込むほか回避するしかないようです。
以上、ご協力ありがとうございました。

Sign in to comment.

Answers (0)

Products

Release

R2019b

Asked:

on 30 Sep 2021

Moved:

on 17 Aug 2022

Community Treasure Hunt

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

Start Hunting!