Writematrix command writing wrong data in Excel sheet
显示 更早的评论
I have an app with different numeric fields displaying the results of certain calculations. The numbers are calculated correctly and stored as doubles (I assume). When I try to store them in a matrix and write this matrix in my Excel file, some of the numbers are incorrect (wrong decimals). This could have something to do with the format Matlab uses to save those numbers. The correct ones are formatted in "standard", the incorrect ones are numbers.
Has anyone experienced a similar problem? How can I fix this?
7 个评论
Johannes
2024-3-5
Dyuman Joshi
2024-3-5
How are the values provided as input and how are they stored? And how do you export the data to excel?
Please share your app, or a minimum working example, which we can run and reproduce the same results as yours and provide suggestions/solutions accordingly.
Johannes
2024-3-5
"This could have something to do with the format Matlab uses to save those numbers"
No, by default MATLAB does not change the cell format. These are the cell formats of the file you uploaded:
- B9: number, 0dp
- B10: number, 0dp
- B11: number, 0dp
- B12: number, general
- B13: number, general
- B14: number, 0dp
- B15: number, general
- B16: number, general
- B17: number, general
However what is more interesting is that some cells contain leading single quotes: this indicates that Excel will force the cell content to be stored as text (this is totally irrespective of the cell format). In your uploaded file, cells B9, B10, B11, B14, B17 store numeric values (or strictly speaking: dynamically typed values), whereas cells B12, B13, B15, B16 store text (with leading single quote indicating content will be stored as text).
Basically that spreadsheet is a bit of a mess. You might find Excel's CELL() function useful to investigate that worksheet:
"Has anyone experienced a similar problem?
Yes, quite often when working with people who do not understand how to use MS Excel.
How can I fix this?"
Do you expect MATLAB to fix your badly formatted file for you?
Open excel. Replace those cells with some fresh, unformatted ones. Save, close, try again.
Johannes
2024-3-19
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Data Import from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!