MATLAB Answers

How can the numbers appears on an excel sheet correctly and not as wierd letters?

조회 수: 1(최근 30일)
Nora Khaled
Nora Khaled 1 Aug 2017
Commented: Nora Khaled 2 Aug 2017
Hi!
I have a problem in writing on an excel sheet. the data is stored correctly but the numbers are not appearing. the code makes 2 excel sheets and the problem is not happening in the first one. the problem happening with the content of excel_timeA', excel_timeB', and excel_timeC'. does anyone have an idea about what could be wrong?
{
% Creat an Excel sheet1:
header1={'car number','car personality'};
cars_personalities=[car_number',car_personality'];
xlswrite('HISTOGRAM',cars_personalities,'cars_histogram');
xlswrite('HISTOGRAM',header1,'cars_histogram');
xlswrite('HISTOGRAM',cars_personalities,'cars_histogram','A2');
% Creat an Excel sheet2:
header2={'Time A','Time B','Time C','Min Time','Player choice'};
data=[excel_timeA',excel_timeB',excel_timeC',excel_numOnRoad',excel_player']; %%%%%
xlswrite('HISTOGRAM',data,'histogram');
xlswrite('HISTOGRAM',header2,'histogram');
xlswrite('HISTOGRAM',data,'histogram','A2');
}

  댓글 수: 0

로그인 to comment.

답변 수 (1)

ES
ES 1 Aug 2017
ES 님이 편집함. 1 Aug 2017
1. Why do you write data twice?
xlswrite('HISTOGRAM',data,'histogram');
xlswrite('HISTOGRAM',header2,'histogram');
xlswrite('HISTOGRAM',data,'histogram','A2');
2. And is the excel file already available? Are the cells formatted?
3. Is the data [excel_timeA',excel_timeB',excel_timeC',excel_numOnRoad',excel_player'] are all numerals?

  댓글 수: 5

표시 이전 댓글 수: 2
Nora Khaled
Nora Khaled 2 Aug 2017
I rewritten the code to be
%Creat an Excel sheet1:
header1={'car number','car personality'};
cars_personalities=[car_number',car_personality'];
xlswrite('HISTOGRAM',header1,'cars_histogram');
xlswrite('HISTOGRAM',cars_personalities,'cars_histogram','A2');
%Creat an Excel sheet2:
header2={'Time A','Time B','Time C','Min Time','Player choice'};
data=[char(excel_timeA'),char(excel_timeB'),char(excel_timeC'),excel_numOnRoad',excel_player']; % this is whats wrong.
xlswrite('HISTOGRAM',header2,'histogram');
xlswrite('HISTOGRAM',data,'histogram','A2');
there is no problem in the first excel sheet. but the second still the same problem.
car_number and car_personality are integers. data contain 2 types : excel_numOnRoad',excel_player' are letters. and excel_timeA', excel_timeB', and excel_timeC' are integers
Walter Roberson
Walter Roberson 2 Aug 2017
If excel_timeA is an integer, then char(excel_timeA') is going to be the kinds of characters you saw. char() of an integer does not format the integer for printing. For example, char(80) does not result in '80': it results in 'P' .
char() is not a format command. char(X) means to take
uint16(floor(X))
and to re-interpret the resulting integer as a 16 bit Unicode character.
double('A')
gives 65, and char(65) gives 'A'.
Each character is handled by linear position. Computers do not store characters in binary any differently than they store integers in binary, using exactly the same range. The difference is only in presentation of the results: if you ask to interpret the integer as a character then the display system looks up the glyph using the integer as the index, and if you ask to interpret the integer as an integer then the display system does the calculations to convert the binary to base 10 and then adds each resulting position to the index for the glyph for '0' (which is 48), and then uses those indices to look up the glyphs for display.
Nora Khaled
Nora Khaled 2 Aug 2017
THANK YOU! the problem is solved.
%Creat an Excel sheet2:
header2={'Time A','Time B','Time C','Min Time','Player choice'};
data1=[excel_timeA',excel_timeB',excel_timeC'];
data2=[excel_numOnRoad',excel_player'];
xlswrite('HISTOGRAM',header2,'histogram');
xlswrite('HISTOGRAM',data1,'histogram','A2');
xlswrite('HISTOGRAM',data2,'histogram','D2');

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by