column added automatically in excel file

조회 수: 3 (최근 30일)
Nidhal Bouzouita
Nidhal Bouzouita 2021년 12월 3일
댓글: Nidhal Bouzouita 2021년 12월 3일
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
Image Analyst
Image Analyst 2021년 12월 3일
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 2021년 12월 3일
i attached here the .mat, the script and the excel output file

댓글을 달려면 로그인하십시오.

채택된 답변

Peter Bonavita
Peter Bonavita 2021년 12월 3일
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
Nidhal Bouzouita
Nidhal Bouzouita 2021년 12월 3일
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 2021년 12월 3일
i used the writematrix api and it works fine ! thx !!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by