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

12 views (last 30 days)
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 Comments
Fatemeh slt
Fatemeh slt on 10 Jul 2021
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 on 10 Jul 2021
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.

Sign in to comment.

Answers (1)

Aditya
Aditya 4 minutes ago
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!

Community Treasure Hunt

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

Start Hunting!