简体   繁体   中英

Import from a specific range of xlsx data in MATLAB GUI

I have a code portion in a MATLAB m.file which import electrical consumption data in an xlsx file. The program will then prompt the user for the grid charges, do the necessary calculation, and then plot a bar chart displaying the consumption cost for every month and the year. The variables obtain in this portion of the code will be use in other parts of the m.file

I then created a multi-page GUI for this m.file using GUIDE, but being a new user in MATLAB, I am struggling with the GUI codings. Especially importing the file, as I want the user to be able to view and select the range of import, and not the entire file. Another thing that I am struggling with is to make data from this GUI available to all the other GUI pages.

The GUI have 2 panels. 1 panel contains 4 edit_text boxes for user to input the grid charges, and a 'Enter' push button. The other panel contains a axes which will be used to display the bar chart, as well as 13 static text which will display value of the monthly and annual cost after calculation is done. I want the axes and 13 static text to display the bar chart and cost data only after the user had filled up the edit boxes with the necessary grid charges, followed by clicking the 'Enter' push button.

I had seen some examples of importing excel files in the GUI, but those I'd seen import the file entirely, or are too hard for someone with little understanding of GUI coding to do. Is there a simple solution to this?

In Matlab, the xlsread function has a parameters where you can specify the sheet and range to read in. http://www.mathworks.com/help/matlab/ref/xlsread.html

For the range parameter, you can specify the range just as in excel

ex.

xlsread('filename', 'A1:B10')

to read in the first 10x2 cells.

However, I suggest you use Microsoft's VBA language in Matlab to import the data depending how large your excel file. I find this method MUCH MORE efficient for larger data sets.

Here is an example of how to use it if you're interested:

excelObj = actxserver('Excel.Application');
fileObj = excelObj.Workbooks.Open(filename);
sheetObj = fileObj.Worksheets.get('Item', sheetnumber);

%Read in ranges the same way as xlsread!
indata = sheetObj.Range('A1:B10').Value;

I do not have much experience with GUI building using guide, but I presume that you need to add callback functions for the components you wish to interact with the user. In those callback functions, you can set a boolean value that indicates whether the user has completed the required actions to start the calculations.

Best of Luck!

use an edit text in the gui in which the user may specify the range of data then u may use xlsread('filename', cell_array), (where cell array contains the string property of the edit text specified previously) in the callback of another push button which u have to design to execute after the user has entered the range. it can be done if u are using GUIDE or creating programatically. Mind my english please its a bit shabby

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM