column added automatically in excel file
3 views (last 30 days)
Show older comments
Nidhal Bouzouita
on 3 Dec 2021
Commented: Nidhal Bouzouita
on 3 Dec 2021
Hello dear community,
i am trying to write those data in the excel sheet :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/822550/image.png)
all the values with 6 digits (with yellow) became different : the comma shifted to the right (like 320,425 for the first yellow one), it looks like the way of writing into the excel shifted it automatically because i debugged it and i found the value before writing into the excel file are correct , any confirmation please ? if so any suggestions ?
I attached the needed files
2 Comments
Image Analyst
on 3 Dec 2021
Make it easy for people to help you. Please attach your variable in a .mat file, and give your code for writing to the workbook.
Accepted Answer
Peter Bonavita
on 3 Dec 2021
Hi Nidhal,
Are the commas (,) in your data intended to represent decimal places? It seems the entry "35,5555" is intended to represent 35.5555. MATLAB uses periods to represent decimal places instead of commas. Thus, when calling xlswrite MATLAB interprets "35,5555" as 35555.
In the Excel sheet you provided, the comma shown in cell A2 is from Excel's number formatting. The raw data is shown as 355555 in the equation editor.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/822620/image.png)
If you want the data to appear directly in the text file including the commas, you can use writematrix (introduced in R2019a):
% write the raw text data to a file without xlswrite
writematrix(Val,'text.xlsx')
The result from writematrix is shown below. Note that in this case, the data in Excel is displayed with the "General" format.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/822625/image.png)
If the commas in your data represent decimal points, you can replace them with periods before calling xlswrite, and MATLAB will treat them as decimals:
newVal = replace(Val,",",".");
TableResult = newVal;
xlswrite(Fileoutput ,TableColumnName,1,'A1');
xlswrite(Fileoutput ,TableResult,1,'A2');
I hope this helps.
Peter
More Answers (0)
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!