column added automatically in excel file

2 views (last 30 days)
Hello dear community,
i am trying to write those data in the excel sheet :
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
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.
Nidhal Bouzouita
Nidhal Bouzouita on 3 Dec 2021
i attached here the .mat, the script and the excel output file

Sign in to comment.

Accepted Answer

Peter Bonavita
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.
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.
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
  2 Comments
Nidhal Bouzouita
Nidhal Bouzouita on 3 Dec 2021
thanks you for your help. actually i can not use newVal = replace(Val,",",".") because sometimes i got for example "12.12" and it is interpreted like "12 Dec" so the excel consider it as date. instead is it possible to use writematrix(Fileoutput ,Val,1,'A2'); ?
actually i am writing a bunch of data i mean i dont have only Val but i have other data to be added , so as you know , the type should be the same for all the data .
Nidhal Bouzouita
Nidhal Bouzouita on 3 Dec 2021
i used the writematrix api and it works fine ! thx !!!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!