help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem when writing a cell array( char and numeric data) to excel(.


From: Tatsuro MATSUOKA
Subject: Re: Problem when writing a cell array( char and numeric data) to excel(.xlsx) file
Date: Thu, 19 Jun 2014 08:49:05 +0900 (JST)

----- Original Message -----

> From: ijourneaux
> To: help-octave
> Cc: 
> Date: 2014/6/19, Thu 05:10
> Subject: Re: Problem when writing a cell array( char and numeric data) to 
> excel(.xlsx) file
> 
> It seems to work for me with MXE Octave 3.8.2 and Excel 2007 using the script
> proposed by dlsquires
> 
> cy1 = ones(1,634); cy2 = ones(1,634)*2; H = 1:634;
> mixed{1, 10}="crctd Y1"; 
> mixed{1, 11}="crctd Y2"; 
> mixed{1, 12}="H"; 
> i=0; 
> for(i=[1:634]) 
>   mixed{i+1, 10}=cy1(i); 
>   i=i+1; 
> endfor 
> i=0; 
> for(i=[1:634]) 
>   mixed{i+1, 11}=cy2(i); 
>   i=i+1; 
> endfor 
> i=0; 
> for(i=[1:634]) 
>   mixed{i+1, 12}=H(i); 
>   i=i+1; 
> endfor 
> xlswrite('crctn.xlsx', mixed, 'First_sheet'); 
> 


I run the same script on octave-3.8.1 (MXE) with io-2.2.2 and create crctn.xlsx.

I watch it by Excel 2010 and LibreOffice Calc 4.4.
The First_sheet exist and it contains J1=crctd Y1, K1=crctd Y2 and L1=H.

I checked mixed on octave:


octave:12> mixed
mixed =
{
  [1,1] = [](0x0)
  [1,2] = [](0x0)
  [1,3] = [](0x0)
  [1,4] = [](0x0)
  [1,5] = [](0x0)
  [1,6] = [](0x0)
  [1,7] = [](0x0)
  [1,8] = [](0x0)
  [1,9] = [](0x0)
  [1,10] = crctd Y1
  [1,11] = crctd Y2
  [1,12] = H
}

It seems xlswrite has no problem but the code

> for(i=[1:634]) 
>   mixed{i+1, 10}=cy1(i); 
>   i=i+1; 
> endfor 


is wrong. So that cell array should not give the result as you wanted

The working code is:

clear all
cy1 = ones(1,634); cy2 = ones(1,634)*2; H = 1:634; 
mixed{1, 10}="crctd Y1"; 
mixed{1, 11}="crctd Y2"; 
mixed{1, 12}="H"; 
 
for n=1:634 
  mixed{n+1, 10}=cy1(n); 
endfor 
for n=1:634 
  mixed{n+1, 11}=cy2(n); 
endfor 
for n=1:634 
  mixed{n+1, 12}=H(n);
endfor 

xlswrite('crctn.xlsx', mixed, 'First_sheet'); 



> for(i=[1:634]) 
>   mixed{i+1, 10}=cy1(i); 
>   i=i+1; 
> endfor 


i=[1:634] should be i=1:634.


>   i=i+1; 

is should be removed. value of i is set incremented value in every loop in the 
array 1:634

Note that on Octave (and also Matlab), i, i, I, and J are imaginary unit 
constants.
Please avoid to use i, i, I, and J as index for loop and use k, m, n, l etcs. 
instead.

Tatsuro

Attachment: crctn.xlsx
Description: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet


reply via email to

[Prev in Thread] Current Thread [Next in Thread]