Writing strings to excel

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Writing strings to excel

rwensley
Greetings,
I have a script that generates a report for a particular test run.
At the end I would like it to create a excel spreadsheet for that particular test.
The first column A2:A33 is to contain the variable name ie. "Test =", "Tester =", etc.
in octave I set up the array as
outArray1=char("tester =","testing =","tested =")
NOTE: I have also tried
outArray1=[tester =","testing =","tested ="]

After setting the filename fn and the worksheet name wsh I enter the following

status = xlswrite (fn, outArray1, wsh,'A2:B33')
with the hope of populating column A with the variable names.

When executed octave returns with
warning: xlswrite - array truncated to 5 by 2 to fit in range A2:B6
(oct2xls: input character array converted to 1x1 cell)
status =  1

And in Excel at cell A2 I have a t.  Just the t and nothing else.

I am sure I am missing something here and any help will be appreciated.

Thank you,
Ron Wensley
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Writing strings to excel

Philip Nienhuis
rwensley wrote
Greetings,
I have a script that generates a report for a particular test run.
At the end I would like it to create a excel spreadsheet for that particular test.
The first column A2:A33 is to contain the variable name ie. "Test =", "Tester =", etc.
in octave I set up the array as
outArray1=char("tester =","testing =","tested =")
NOTE: I have also tried
outArray1=[tester =","testing =","tested ="]

After setting the filename fn and the worksheet name wsh I enter the following

status = xlswrite (fn, outArray1, wsh,'A2:B33')
with the hope of populating column A with the variable names.

When executed octave returns with
warning: xlswrite - array truncated to 5 by 2 to fit in range A2:B6
(oct2xls: input character array converted to 1x1 cell)
status =  1

And in Excel at cell A2 I have a t.  Just the t and nothing else.

I am sure I am missing something here and any help will be appreciated.
Both

outArray1=char("tester =","testing =","tested =")
   &
outArray1=[tester =","testing =","tested ="]

will give you a character array.

I think what you need is a cell array:

outArray1={"tester =";"testing =";"tested ="}  ## Note: semicolons to make it a 3x1 rather than 1x3 array

If I try that (with your xlswrite command) I get a spreadsheet with

tester =
testing =
tested =

in cells A2:A4.

xlswrite.m's (or rather oct2xls.m's) complaints about the sizes and ranges are intriguing. I'll look into that.

BTW what io package version and Octave version do you use?
Try:

ver

at the command prompt, it'll echo a listing of Octave version and versions of all installed packages (I only need Octave and io package versions)

Philip
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Writing strings to excel

Przemek Klosowski-7
In reply to this post by rwensley
On 06/26/2017 02:27 PM, rwensley wrote:
At the end I would like it to create a excel spreadsheet  [...]
status = xlswrite (fn, outArray1, wsh,'A2:B33') 
Strings in Matlab arrays are a little awkward, and don't mix well with numbers; you probably need cell-based data.
Actually, would writing a CSV file work for you? Excel can read CSV format just fine and it's much easier to generate in Octave because it's just strings:

fp=fopen('a.csv','w')
a1=char("a =","bbbb =","c =")
a2 =[1   2   3]
for i=1:3; fprintf(fp,"%s,%f\n",a1(i,:),a2(i));end

giving

a =   ,1.000000
bbbb =,2.000000
c =   ,3.000000


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Writing strings to excel

rwensley
In reply to this post by Philip Nienhuis
Philip,

Thank you for the reply.

I have octave v4.2.1 and io v2.4.5

I will try recommendation and let you know how it worked out.

Ron
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Writing strings to excel

Philip Nienhuis
rwensley wrote
Philip,

Thank you for the reply.

I have octave v4.2.1 and io v2.4.5

I will try recommendation and let you know how it worked out.
What you could do anyway is upgrade to io-2.4.7.
I'm unsure if Octave-4.2.1 can upgrade using the -forge flag:

pkg install -forge io

otherwise (if you get errors there) you'd have to manually dowload io-2.4.7.tar.gz, in Octave browse to its location and do:

pkg install io-2.4.7.tar.gz

Philip
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Writing strings to excel

rwensley
In reply to this post by Philip Nienhuis
Philip,

That worked great. Thank you for your help.

Ron
Loading...