From: Jos on
Hi,

I have a cell array of numbers and want to write it into a cell array of strings (this is because besides numerical input, there will also be added strings to the table. After this, the table of strings is printed to excel

this is the input:
4 3,69599639557127 188,410000000000 86,0893000000000
6 7,08828645208912 274,569000000000 97,3328000000000
8 9,38747390641889 349,375000000000 102,099000000000
10 10,9083049302071 447,311000000000 120,367000000000
12 11,3831813630739 448,195000000000 157,617000000000
14 12,9220834663217 452,480000000000 159,910000000000
16 15,2383797236977 459,235000000000 327,560000000000
18 22,1045498361762 483,264000000000 346,441000000000
20 37,8022334739675 486,764000000000 452,589000000000
22 55,6718604320812 519,297000000000 479,373000000000
24 76,8186179083778 557,011000000000 510,505000000000

And this is what appears in the table of strings:
' 4' ' 3.696' ' 188.41' '86.0893'
' 6' '7.08829' '274.569' '97.3328'
' 8' '9.38747' '349.375' '102.099'
'10' '10.9083' '447.311' '120.367'
'12' '11.3832' '448.195' '157.617'
'14' '12.9221' ' 452.48' ' 159.91'
'16' '15.2384' '459.235' ' 327.56'
'18' '22.1045' '483.264' '346.441'
'20' '37.8022' '486.764' '452.589'
'22' '55.6719' '519.297' '479.373'
'24' '76.8186' '557.011' '510.505'

But when I use xlswrite, the excel file gives this:
4 3.696 188.41 860.893
6 708.829 274.569 973.328
8 938.747 349.375 102.099
10 109.083 447.311 120.367
12 113.832 448.195 157.617
14 129.221 452.48 159.91
16 152.384 459.235 327.56
18 221.045 483.264 346.441
20 378.022 486.764 452.589
22 556.719 519.297 479.373
24 768.186 557.011 510.505

Anyone with an idea of why this happens?
From: dpb on
Jos wrote:
> Hi,
>
> I have a cell array of numbers and want to write it into a cell array
> of strings (this is because besides numerical input, there will also be
> added strings to the table. After this, the table of strings is printed
> to excel
>
> this is the input:
> 4 3,69599639557127 188,410000000000 86,0893000000000
> 6 7,08828645208912 274,569000000000 97,3328000000000
....
> And this is what appears in the table of strings:
> ' 4' ' 3.696' ' 188.41' '86.0893'
> ' 6' '7.08829' '274.569' '97.3328'
....
> But when I use xlswrite, the excel file gives this:
> 4 3.696 188.41 860.893
> 6 708.829 274.569 973.328
....
What did you use to write the strings? You'll need to use a method that
allows a format instead of the default of (say) num2str that assumes
something else. See optional arguments for num2str and/or sprintf()

doc num2str

--
From: Jos on
The input was transformed (in a for loop) to a string using (simplified code):
tab_strings=cellstr(num2str(input))
And tab_strings has what I expect from it (so a cell array of strings with the correct numbers). It is only when using xlswrite('path',tab_strings) that something goes wrong.

dpb <none(a)non.net> wrote in message <hf38r8$4ku$1(a)news.eternal-september.org>...
> Jos wrote:
> > Hi,
> >
> > I have a cell array of numbers and want to write it into a cell array
> > of strings (this is because besides numerical input, there will also be
> > added strings to the table. After this, the table of strings is printed
> > to excel
> >
> > this is the input:
> > 4 3,69599639557127 188,410000000000 86,0893000000000
> > 6 7,08828645208912 274,569000000000 97,3328000000000
> ...
> > And this is what appears in the table of strings:
> > ' 4' ' 3.696' ' 188.41' '86.0893'
> > ' 6' '7.08829' '274.569' '97.3328'
> ...
> > But when I use xlswrite, the excel file gives this:
> > 4 3.696 188.41 860.893
> > 6 708.829 274.569 973.328
> ...
> What did you use to write the strings? You'll need to use a method that
> allows a format instead of the default of (say) num2str that assumes
> something else. See optional arguments for num2str and/or sprintf()
>
> doc num2str
>
> --
From: dpb on
Jos wrote:
> The input was transformed (in a for loop) to a string using (simplified code):
> tab_strings=cellstr(num2str(input))
> And tab_strings has what I expect from it (so a cell array of strings
> with the correct numbers). It is only when using
> xlswrite('path',tab_strings) that something goes wrong.

That certainly isn't what the output you showed previously
indicates...nor what I would expect the result of num2str() to be w/ the
default formatting.

....

>> x=pi
x =
3.1416
>> num2str(x)
ans =
3.1416
>> format long
>> x
x =
3.14159265358979
>> num2str(x)
ans =
3.1416
>> length(ans)
ans =
6
>> num2str(x,15)
ans =
3.14159265358979
>>

--
From: Jos on
So what you are saying is that you would also expect the correct data to be written to xls?
Is there a way to format tha data when using xlswrite?

dpb <none(a)non.net> wrote in message <hf3vb8$20f$1(a)news.eternal-september.org>...
> Jos wrote:
> > The input was transformed (in a for loop) to a string using (simplified code):
> > tab_strings=cellstr(num2str(input))
> > And tab_strings has what I expect from it (so a cell array of strings
> > with the correct numbers). It is only when using
> > xlswrite('path',tab_strings) that something goes wrong.
>
> That certainly isn't what the output you showed previously
> indicates...nor what I would expect the result of num2str() to be w/ the
> default formatting.
>
> ...
>
> >> x=pi
> x =
> 3.1416
> >> num2str(x)
> ans =
> 3.1416
> >> format long
> >> x
> x =
> 3.14159265358979
> >> num2str(x)
> ans =
> 3.1416
> >> length(ans)
> ans =
> 6
> >> num2str(x,15)
> ans =
> 3.14159265358979
> >>
>
> --
 |  Next  |  Last
Pages: 1 2 3 4
Prev: java and simulink
Next: mincx to gevp