MATLAB changes the number of digits after the decimal when I export my data from the excel

14 ビュー (過去 30 日間)
Fatemeh slt
Fatemeh slt 2021 年 7 月 10 日
回答済み: Aditya 2024 年 11 月 21 日 6:25
Hello all,
I am a new user of MATLAB. My data in excel contains 10 digits after the decimal place, I have set the MATLAB's style format to longG, tho when I open my excel file in MATLAB and import my data, it shows the numbers only with 4 digits after the decimal. for example:
0.9768069967 in the excel coverts to 0.9768 in the MATLAB.
I would be grateful if anybody could help me on that.
  3 件のコメント
Fatemeh slt
Fatemeh slt 2021 年 7 月 10 日
I used this syntax on the command line: format longG
I also check it in the preference and it was chosen as the style.
Stephen23
Stephen23 2021 年 7 月 10 日
The FORMAT command only affects how data are displayed, it has absolutely not effect on how data are imported.
Suffice to say, your data will be imported to whatever precision the data has, that can be supported by the data class.
If you upload a sample file by clicking the paperclip button, then we can take a look at it.
So far you have not given any explanation or even a hint as to how you imported the data.

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

回答 (1 件)

Aditya
Aditya 2024 年 11 月 21 日 6:25
Here's is a sample code which you can use to see whether the data is being exported correctly inside MATLAB:
I have created a sample 'xlsx' file for the testing:
% Define a matrix with sample numbers
sampleData = [
0.9768069967, 1.2345678901;
3.4567890123, 4.5678901234
];
% Specify the file name
fileName = 'SampleData.xlsx';
% Write the matrix to an Excel file
writematrix(sampleData, fileName);
Export the 'SampleData.xlsx' file and see the results:
% Import data from Excel
data = readmatrix('SampleData.xlsx');
% Set display format to longG
format longG
% Display the data
disp('Imported Data:');
disp(data);
% Check the class of the data
disp('Data Type:');
disp(class(data));
I have tried this on MATLAB R2021a and it was working correctly.
To read more about other display format options for numeric values refer to this documentation:
Hope it helps!

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by