SciLab import excel question

Messages about other areas of TRIUS expertise (Energy, Radiation Safety, Risk,..) and Technology, in general...
Post Reply
User avatar
NanoSci
New User
New User
Posts: 4
Joined: Sun Nov 05, 2017 11:00 pm

SciLab import excel question

Post by NanoSci »

This is not related to nuclear, but I have been trying to access and use an excel file in scilab and I am having all sorts of problems. Is anyone here familiar enough to help me? Please!
User avatar
NumCruncher
New User
New User
Posts: 6
Joined: Mon Nov 06, 2017 3:03 pm

Re: SciLab import excel question

Post by NumCruncher »

NanoSci wrote: Mon Nov 06, 2017 3:12 am This is not related to nuclear, but I have been trying to access and use an excel file in scilab and I am having all sorts of problems. Is anyone here familiar enough to help me? Please!
Can you provide some detail as to what sorts of problems you are having? Is there an error message? something specific you don't know how to do? I think I am familiar enough to help, but I need to know what help you need :shock:

BTW, accessing an excel file is pretty easy using the readxls function in Scilab. You may also use xl_open and xl_read.

Anyway, give me something to work with and I will try to help.
User avatar
NanoSci
New User
New User
Posts: 4
Joined: Sun Nov 05, 2017 11:00 pm

Re: SciLab import excel question

Post by NanoSci »

Thanks. I am a novice at this. I apologize if I did not provide enough detail. And, I've tried to read the on-line help, before posting here.

So, the documentation says to use

[fd,SST,Sheetnames,Sheetpos] = xls_open('SCI/modules/spreadsheet/demos/xls/Test1.xls')

to open the file In my case, my file is Annual_Variations.xlsx. I tried

[fd,SST,Sheetnames,Sheetpos] = xls_open('C:/Sim/DataCollections/xlsx/Annual_Variations.xlsx')

and it does not work. What am I doing wrong?
User avatar
NumCruncher
New User
New User
Posts: 6
Joined: Mon Nov 06, 2017 3:03 pm

Re: SciLab import excel question

Post by NumCruncher »

I'm pretty sure that XLSX files are not supported. Only xls files. That may be your problem. What is the error message you are getting, anyway?
User avatar
NanoSci
New User
New User
Posts: 4
Joined: Sun Nov 05, 2017 11:00 pm

Re: SciLab import excel question

Post by NanoSci »

NumCruncher wrote: Mon Nov 06, 2017 6:49 pm I'm pretty sure that XLSX files are not supported. Only xls files. That may be your problem. What is the error message you are getting, anyway?
Thank you. I saved the file as XLS and that seems to have fixed it. Any idea why xlsx are not supported?

Also, I know there is documentation on line, but I am trying to read it and not all makes sense to me. I am trying to read in the excel file (primarily values), view the results on the console (it actually has 2 sheets) and then graph the results in sheet(1) and sheet(2).

Any shortcuts or anything you can suggest?
User avatar
NumCruncher
New User
New User
Posts: 6
Joined: Mon Nov 06, 2017 3:03 pm

Re: SciLab import excel question

Post by NumCruncher »

Well, as always, the devil is in the details, but here is a sample of how you could do this...


sheets = readxls('C:\excel_graph01.xls') // This should point to a valid file
s1=sheets(1) // Get Sheet(1)
disp(s1.value(),"Values in Sheet(1)") // Display the values in Sheet 1
disp(s1.text(),"Strings in Sheet(1)") // Display text in Sheet 1
s2=sheets(2) // Get Sheet(2)
disp(s2.value(),"Values in Sheet(2)") // Display the values in Sheet 2
disp(s2.text(),"Strings in Sheet(2)") // Display text in Sheet 2
// For the purposes of this example, let's propose that column A in sheet(1) and column C in Sheet(2) contain the
// numeric values you want to plot. We'll use two temp arrays to store the values.
ValSheet1=s1.value
plot(ValSheet1(:,1))
// or, to plot the sheet(2) values
// ValSheet2=s2.value
// plot(ValSheet2(:,3))

You can get a lot more specific and imaginative, but this should meet your basic requirement to view and plot the data.
User avatar
NanoSci
New User
New User
Posts: 4
Joined: Sun Nov 05, 2017 11:00 pm

Re: SciLab import excel question

Post by NanoSci »

Thanks. I can't claim that I understand everything you are doing in this code, but I will look at it closely and try to understand. I did try it as is (with a small excel file and it worked).

Thank you again.
Post Reply