I had a chance to work with a MATLAB user that was interested in bringing her Excel data into MATLAB and plotting different variables. This was a fairly standard file format, just columns of data. It was pretty easy to read in the data with XLSREAD:
Note that three minutes into the video above, I use a neat cell mode trick that many might not know about.
Once this was done, it was time to turn that script into a function so that it could be reused easily.
Finally, the function needed a GUI to make it easy to view any piece of data from the file.
I completely agree that it would be nice to see the entire command line. The trade-off I am struggling with is I can only make the screen so wide if I want to embed the video in a web page. I could zoom out, but then the text is illegible.
I will try to use …
short commands or …
the commands can be …
continued like this …
so they all fit on …
screen at once.
If anyone has any other ideas, please let me know. I can make the videos taller and fit in the blog, but 500 pixels wide is all that fits nicely here (that is still 180 more across than I could get on YouTube)
I got a problem when reproducing the Excel-plotting GUI… I guess I am missing something so the outcoming GUI stands by itself fine.
Here is what it happened:
While I was running the GUI from GUIDE or its M-file, everything was ok. When I opened MATLAB again (during a new session) and clicked the .FIG file on the Current Directory Window, the GUI appeared, but it started to produce the following errors:
??? Reference to non-existent field ‘popupmenuX’.
Error in ==> PlotExcelGUI>pushbuttonLoadXLS_Callback at 140
setPopupmenuString(handles.popupmenuX, eventdata, handles)
Error in ==> gui_mainfcn at 95
Error in ==> PlotExcelGUI at 42
??? Error using ==> PlotExcelGUI(‘pushbuttonLoadXLS_Callback’,gcbo,,guidata(gcbo))
Reference to non-existent field ‘popupmenuX’.
??? Error while evaluating uicontrol Callback
How can I make the .FIG file to run my GUI without getting into GUIDE each time?
I tried downloading the mainGui.fig, mainGui.m and the excel file so I can run it, and the gui came up just fine, but once I selected the excel file, I got some callback errors:
?? Reference to non-existent field ‘popupmenuX’.
Error in ==> mainGui>pushbuttonLoadXLS_Callback at 130
setPopupmenuString(handles.popupmenuX, eventdata, handles)
Error in ==> gui_mainfcn at 75
Error in ==> mainGui at 42
??? Error while evaluating uicontrol Callback.
Thanks for the prompt replay. I’m gonna ping you on something that I’m having a great deal of difficulty with. And that is, I have a text file pretty much the same format as the excel example you have. The first row is the header row (string) that specifies the names for the columns (numbers). How can I adapt your code to my needs? My goal is to come up with the gui that gives you the option to pick and choose which columns go to x and y, just like you have in your example. I think the key difference is knowing what ‘xlsread’ actually does. I’m using ‘textread’, but the real problem is the first row is a string, which ‘textread’ won’t read in. I can get ‘textread’ to read in the first column strings, but then I’ll need a separate ‘textread’ to read in the rest of the numbered data. Do you see how it complicates things?
Thank you very much for your videos, I am a final year electrical engineering student and your videos have helped me produce MATLAB code that will be really useful in compleating my final year project.
I have a similar question about importing excel data into matlab, but about a more complicated type of file. My excel files has a lot of text near the top, and then many columns of data with x-y-z locations for 3-D points. After ALL of this data, there’s some more text, and then EMG data. I want to write a function to read through past the text, find the columns of data I’m interested in, and store them in their own variables. Do you know how I would go about doing this?
This is getting into reading custom formats inside of an Excel file. MATLAB gives you the ability to read an arbitrary range inside of an Excel file, and the ability to parse those results. These are the low level functions that are need to accomplish this goal. There is no built-in function that will do what you want since files can vary so much. However, you should be able to build your own.
I want to know if it is possible to write data into an excel files using GUI Matlab program ??
Right now I am going to develop a big program that takes data from first users and make several kinds of calc as an output … excel file it is suppose to store these results (by Matlab supervision of course)… and for other users it is should to review latest results , makes same calc and then makes it is Owen results in different excel files …..
Is there any advice U can give me here?
My question is can i run an m file from excel sheet? i know i can read data from excel sheet and do calculations in matlab and then return the data to the excel sheet but this requires running of the m file. I am in the process of developing a userfriendly software and i feel combination of excel with VB will be more fit for the purpose. Please do reply.
I am trying to plot data in 3D. I have degrees for axis 1 across the top, degrees for axis 2 down the side, and the data (which will be the Z-axis) are what is in the matrix. How do I modify the mainGUI to incorporate x,y, and z and recognize that there isn’t a “heading” for the column 1 since that is actually one of the axis and not the data itself.
I would like to merge data files from a few .xls files in one .mat file. Since in .xls file the max no. of column is 256 but I need 600 columns for my input data. That’s why I split data in few .xls files. I know that I can do it by cut and paste the data in .mat file but it will be time consuming. Is there any other way to do it? Please help. Thanks
Dear Doug Hull,
I have seen your tutorials and I have to admit that I have learned a lot thanks to your efforts.
While watching the tutorials I noticed that there aren’t any which covers the table component to be used as UI in order to collect and save editable data in a file in order to eliminate the dependency of Excel. I have tried to search for a hint but failed to find any which helps. I wonder if you are kind enough to show likes of me a hint on how to save editable data from a table to a file and then load it back to the table.
Hi Doug, thanks for your video about reading an Excel file from Matlab. I am pretty new to Matlab but I have been presented with a project to work on that I think Matlab will help with.
I have an Excel sheet with a lot of data that I need to make searchable for specific user-defined values. (I was thinking of putting in some user prompts). It seems like xlsread reads the entire Excel file, or a range of cells in the file. For my purposes I will only need to read one or a few cells at a time. Then I need to load a DLL for a data analysis program I have (I was thinking about using the Matlab Generic DLL Interface), and call specific functions to operate on the data, and then I was thinking about using xlswrite to print the results to a new worksheet or to the next page within the same Excel file.
For example, I run the program and I happen to be interested in Temperatures between 95 and 100. So I search for all of these values that might be in the Excel file, then let’s say I have a function in my DLL file called TEMP2. I would call that function and use it to process these temperatures.
Do you think I am on the right track? Could you possibly help me figure out how I can accomplish this?
Basically what’s hard for me is wading through the syntax when first starting out, it’s not obvious to me what certains commands do unless I can see an example of where it is used.
I am pretty good at adapting examples to my specific problem.
The main concerns I have is that the DLLs I have won’t be compatible with the Matlab DLL Interface and I’ll end up using a Fortran script (which is originally what the data software people recommend, but what do they know about Matlab?)
Following your fantastic tutorial, I try to create a GUI bringing my Excel data and doing some calculations. My excel file has 20 worksheets(20 subjects), and each worksheet has data. These are part of my code:
It updates all sheet names on popup menu. Then I want it automatically updates data when I select different name from popup menu. So my question is how to get data from each sheet? I tried “get(handles.popupmenu1, ‘value’)” but it doesn’t work.
Any help will be highly appreciated! Thanks.
It is not clear to me the specific question you need answered. I think you have a pop-up menu that is correctly populated with the various sheet names from your Excel file. From there, you want to figure out the name of the sheet that was selected in the pop-up.
Value will give you an ordinal number. You need to then use this number to index into the cell array that is stored in the ‘string’ property to get the actual string that represents the sheet name.
Look this is a great video but for a person totaly new to MATLAB there is a big problem in this tutorial. You need to identify what each code means. you say something like: setPopupmenuString(handles.PopupmenuX, eventdata, handles) what is setPopupmenuString? what are handles? setPopupmenuString (you never explain what is needed in here, what does it mean? Why you need it?)
the first two videos are fairly easy to understand but the last one is abit confusing because I did not know what code to start with. I think you should explain in more detail why you should type this code? what does it does? one after every line. thanks
Hi Ive tried the same method used for unidentified files witout any suffix and I failed. What modifications to the codes you need to do for an unidentified file to get the same result as this tutorial?
There is always the difficult decision on how much detail I need to discuss in a video. This third video was already 13 minutes, nearly three times the average length. Sometimes, details need to be skipped.
There are plenty of other video that discuss the questions you have, like what is “handles”
I have recently built up a GUI which has multiple functionality of downloading Documents from an ftp server, listing dir and opening local files. what I want to do next is include a window on the GUI where I can load an excel sheet on it. i.e. have GUI like a remote desktop for that spreadsheet where I can modify/change/save…ect the data.
I have managed to add Microsoft office spreadsheet 11.0 activeX, but when implementing it within the GUI, it doesn’t ask me for which spreadsheet I want to open instead it loads a blanc one and everytime I export the data to Mic Off excel it saves it automaticaly under a different excel file.
I can open the file with the following matlab commands but I can’t really manage to link it to open within the GUI:
The documentation on how to interact with actX controls is with the maker of the control, so there is not much I can do to help you here. I would check with the maker of the control to look for documentation on it.
Thanks for the kind words. You can only select one value from a pop-up. Change it to a list box and change the MAAX property (weird, I know) so it is multi-select. The rest would be a matter of changing the plotting code to deal with all the selected values.
I am trying to export a ‘figure’ and some Numerical data into excel. I first save’figure’ using ‘activx’ and then I write numerical data using ‘xlswrite’. but everytime matlab overwrites the existing data in excel. Is it not possible to write both figure and data with just matlab commands(without installing any other tools)? Please help.
i want to use same filename. and i want to write one figure and under that some numeric data. If i write figure first using activx and then use xlswrite to write numeric data then figure is gone and only numeric data remains and vice versa.
If I added a second axes on the GUI, how would I implement the code to plot two different graphs on the same GUI? Both plots are coming from the data that is read into Matlab from excel, just like the tutorial shows. I just want to be able to produce two plots in one GUI.
What have you tried. Where is the stumbling point? Adding a second axis, are both plots going to the same axis? You should capture the handles from each axes and use them as inputs into the plotting functions.
It seems the same plot ends up on both axes. I tried to implement a plot axes pushbutton for both axes. This is what I have for code under the plot axes pushbutton.
function PlotAxes1_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to PlotAxes1_pushbutton (see GCBO)
% eventdata reserved – to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
fileName = handles.fileName;
[x,y] = readExcelcolumns(fileName, xcolNum, ycolNum)
plot (handles.axes1, x,y)
axis ([320 400 0.760 0.900])
This plots on both axes. When I try the next function plot axes2 pushbutton it does not seem to plot the data into axes2. The axes1 data plots in both axes1 and axes2
I am a newbie to programming and have chosen MATLAB to start with. I want to make MATLAB a better alternative to Excel for my research purposes. Your videos are helping me finding a way through. Thank you for that!
I have to generate graphs from several (thousands) of CSV files generated from simulation runs. These CSV files have yearly-hourly values of different variable such Air temperature, humidity, etc. That means in one file I usually have to deal with 8760 rows (for no. of hours in an year) and many columns. And when the files are in thousands of number, then I have a huge data to process.
I have two questions from you, which are:
1.The first column array of the CSV file is in Date-Time format e.g. “01/01/2012 01:00:00″ and so on. When I import this file into MATLAB it separates this Date-Time column from the rest of the data, and treats it as a text data. So how can I plot a graph between this Date-Time column and the other data columns. Do I have to convert this date-time values into numeric values and then bring it to MATLAB, but then I have to match between year 1900 date-time format of csv and year 0000 date-time format of MATLAB. What is the best way to deal in such situation?
2. How to deal with multiple files since many times I have to plot graph between column arrays from different files?
I would appreciate, if you can give some momentum to my programming learning.
PS: I can send you a copy of the CSV file, if you wish to look into it. Please let me know how I can send it to you.
For some reason when I’m trying to xlsread a specific range of rows and columns from he exel file, I get the following error:
Warning: Could not start Excel server for import, ‘basic’ mode will be used. Refer to HELP
XLSREAD for more information.
> In xlsread at 186
In exelDTV at 1
Warning: Range cannot be used in ‘basic’ mode. The entire sheet will be loaded.
> In xlsread at 199
In exelDTV at 1
Where exelDTV is my assigned variable. I tried looking at row 186 and changing value of ‘Basic = true’ to ‘false’ but it didn’t work,I just get more errors. The help section says that I cannot use range command unless I have a machine running Windows OS with exel installed on it, which I do. Is there any way to fix this issue?
I also have this problem that a couple of people here seem to have. When I copy the callback from property inspector I get an error that says that ‘Undefined function or variable ‘hObject’.’ For some reason your callback string has ‘gcbo’ instead of my hObject and  instead of my ‘eventdata’. What could be the reason for this? Matlab version is 184.108.40.2069 (r2012a)
As stated in our documentation: The full functionality of XLSREAD depends on the ability to start Excel as a
COM server from MATLAB. If your system does not have this capability (as on a non-Windows platform
such as a Mac or Linux machine), the XLSREAD syntax that passes the ‘basic’ keyword is recommended.
As long as the COM server is available, you can use XLSREAD on Excel files having formats other than
XLS (for example, HTML).
I am new to MATLAB and really the Video Tutorials helps a lot in understanding GUI feature of it.
Question:I had followed all the above steps and when I run .m file, figure window opens and I loaded Excel file but when I came to choose the column to plot following error is occurring.Can you please tell me where is the problem..??
Following is shown in command window::
Sorry, I was not too specific. The weird problem is that I am using Windows XP 64 bit with Excel installed on it. I asked my system administrator if Excel is running virtually, but this seems to be not the case. What could be the issue? I tried reinsalling excel already. Really need help here!!
Doug,thank you so much for all your help, you are literaly doing god’s work! But I’ve got another issue. I tried compiling that software we created in this tutorial and everything works fine until I upload an excel document-nothing hapens. It’s as if the excel document is not stored in the program. How can I fix this problem? Again,sorry for being so annoying with all those questions!
I am not 100% sure what you mean by that, but here’s what my file selection process looks like:
I have an .xls file in folder ‘A’
I compiled the script and put it in a folder ‘B’
When I launch software,everything seems to work fine, but once press load.xls button, find the file and select to open it, nothing happens. The files I compiled were:
Main file> .m file we created
Additional file> .fig file with the gui layout and my background picture.
I tried doing it on 2 different computers and even created a different function with uigetfile command in it, and the issue is always the same. It seems like uigetfile command is not supported by compiler or some important files are missing. Thanks for your help!!!
I am working developing a GUI, i have to take a excel file, and do some plots, OK so far no problem, but I would like to be able to take the excel file from a different folder which is always random, With uigetfile I can only get the file in the same folder that I am. I see that is a similar problem than the @Glen, but he does not say what the solution is.
i will appreciate your help a lot, even if you want I can send you the script.
Thank you very much!!
Yes sorry, i didn’t explain it very well. when I pres the button LoadXLS it opens a window, if i have the excel file in that window the GUI works perfect. But if I have to take the excel file from another folder,I can change the folder, but when i select the file I have this error:
Sir,I am unable to dump the contents of excel sheet into the uitable created in GUI.*I am using data from excel sheetes to write matlab programs. Also I have crating a GUI containing all the program codes. But i want to display the data in a uitable from the excel sheets and I am unable to do it. I have wriiten the following code
From the above code table is created in a new figure with specified rows and columns. But the entries contains some redundant data and i havent provided any path to excel. I don’t want to use ‘rand’command which grenerates redundat data while I want to store excel sheet contents in uitable.How can I do this?
Pretty helpful video. However, I have one question which I hope you could clarify. I am using my GUI to load 2 different excel files and then plot different plots using the data loaded for the comparision purposes. So when I upload one “.xlsx” file, it plots whatever I want using the GUI. Then when I upload my second “.xlsx”file, it plots every parameter I want to. However, the problem which I am facing is that now if I use the pop-up-menu of my first .xlsx file to plot a new or different plot, it doesn’t work and shows me an error in calling the “readExceldata” function. Thus, the problem is that if I load a new excel file using the push-button, I am unable to gain access to the previous loaded excel file and I need to load it again for accessing it. I have used different callback funcitions for both push-buttons and hence, have different fileNames. I am unable to understand why is this haapening. Any guidance is highly appreciated.
In the 3rd video you have explained how the data in the excel file can be used through out the GUI using the sytax guidata(hObject, handles). What do we need to do if we have two excel files? or some other thing which even should be available through out the gui?
Is this possible? If so how can this be implemented. Looking forward for the answer.