How can the numbers appears on an excel sheet correctly and not as wierd letters?
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
ES
on 1 Aug 2017
Edited: ES
on 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 Comments
Walter Roberson
on 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.
See Also
Categories
Find more on Data Import from MATLAB 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!