help for loading an empty excel sheet in matalb gui table

1 view (last 30 days)
Hi..i am a newbie in matlab..for my project i have a requirement to load an empty excel sheet, enter the data which gets saved in the excel sheet and display the data graphically. For now i just wrote a simple code for loading en empty excel sheet, when i add the data in the cells of the gui table it throws me some segmentation exception, while if i load an excel sheet which already has some data and then add some data and save it, it does not throw any exception. Can anyone please help me with this problem..(following is a simple code, it is just a trial code, as i wanted to see if it works with empty excel sheet..Name of my excel sheet is 'excelSheet'..and just for trial i am working with first three columns, 'A', 'B' and 'C')..thanks
function uitable1_CellEditCallback(hObject, eventdata, handles)
% hObject handle to uitable1 (see GCBO)
% eventdata structure with the following fields (see UITABLE)
% Indices: row and column indices of the cell(s) edited
% PreviousData: previous data for the cell(s) edited
% EditData: string(s) entered by the user
% NewData: EditData or its converted form set on the Data property. Empty if Data was not changed
% Error: error string when failed to convert EditData to appropriate value for Data
% handles structure with handles and user data (see GUIDATA)
excelSheet = getappdata(0, 'excelSheet');
arith = getappdata(excelSheet, 'arith');
get_tableData = get(hObject, 'data');
xlswrite('trialSheet.xlsx', get_tableData(:,1), 'A1:A3');
a_val = get_tableData(:,1);
setappdata(excelSheet, 'a_val', a_val);
xlswrite('trialSheet.xlsx', get_tableData(:,2), 'B1:B3');
b_val = get_tableData(:,2);
setappdata(excelSheet, 'b_val', b_val);
xlswrite('trialSheet.xlsx', get_tableData(:,3), 'C1:C3');
c_val = get_tableData(:,3);
setappdata(excelSheet, 'c_val', c_val);
column_names = {'A', 'B', 'C'};
set(handles.uitable1, 'Data', get_tableData, 'ColumnName', column_names, 'ColumnEditable', true);
plot(a_val,b_val);
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% excel_data = get(handles.uitable1, 'data');
arith = xlsread('trialSheet.xlsx');
arith = [arith; repmat(0,1,size(arith,2))];
setappdata(excelSheet,'arith',arith);
column_names = {'A', 'B', 'C'};
set(handles.uitable1, 'Data', arith, 'ColumnName', column_names, 'ColumnEditable', true);

Answers (2)

Walter Roberson
Walter Roberson on 8 Aug 2011
What are you expecting getappdata(0, 'excelSheet') to return?
Is there a reason why you set(handles.uitable1, ...) instead of set(hObject,...) since you know that the table you want to affect is the same as the one you are editing?
You have get_tableData = get(hObject, 'data'); and then you do not change get_tableData before you set(handles.uitable1,'Data',get_tableData,...) so you are writing back the same data that is already there. Is there a reason for that?

sneha
sneha on 8 Aug 2011
Edited: Jan on 30 Oct 2017
i am using getappdata(0, 'excelSheet') in order to avoid global variables, name of my m file is 'excelSheet', oops i am sorry name of my excel sheet is 'trialSheet.xlsx'. In my opening function i have used excelSheet = hObject; setappdata(0,'excelSheet',excelSheet); as follow
function excelSheet_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to excelSheet (see VARARGIN)
% Choose default command line output for excelSheet
handles.output = hObject;
excelSheet = hObject;
setappdata(0,'excelSheet',excelSheet);
i do not assume set(handles.uitable1, ...) is a problem, infact i even tried it with set(hObject,..) it still throws me same exception..so i do not where is the problem, i think it is to do with "arith = [arith; repmat(0,1,size(arith,2))];" line..but i am not too sure..following is the exception it throws:
------------------------------------------------------------------------
Segmentation violation detected at Mon Aug 08 02:17:18 2011
------------------------------------------------------------------------
Configuration:
MATLAB Version: 7.8.0.347 (R2009a)
MATLAB License: XXXXXX
Operating System: Microsoft Windows Vista
Window System: Version 6.1 (Build 7601: Service Pack 1)
Processor ID: x86 Family 6 Model 5 Stepping 2, GenuineIntel
Virtual Machine: Java 1.6.0_04-b12 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode
Default Encoding: windows-1252
Fault Count: 1
Register State:
EAX = 0ddb7370 EBX = 00000000
ECX = 1d3bdec8 EDX = 00000008
ESI = 00000000 EDI = 00000000
EBP = 00c2b3ec ESP = 00c2b3d0
EIP = 788b07f8 FLG = 00010212
Stack Trace:
[0] hg.dll:struct mxArray_tag * __cdecl CreateNumericPreviousDataHelper<6>(struct mxArray_tag *,int)(0x0dd9ebe0, 0, 0x789cd070, 0x00c2b440 "l´Â") + 72 bytes
[1] hg.dll:struct mxArray_tag * __cdecl CreateNumericPreviousData(struct mxArray_tag *,int)(0x0dd9ebe0, 0, 0x789cd070, 0x20f90560) + 52 bytes
[2] hg.dll:struct mxArray_tag * __cdecl celledit_event_data(struct GObject_tag *,void *)(0x20f90560, 0, 0x793e5f70, 0x0ac8c018) + 246 bytes
[3] hg.dll:_uitableCellEditHandler(0x20f90560, 0x789cd070, 0x00c2b4b4 "Ì´Â", 0x78864bd6) + 66 bytes
[4] hg.dll:public: virtual void __thiscall UITableGObjectDisplayManagerModel::CellEditHandler(void *)(0x789cd070, 0x00c2b584, 0x20deefac, 0x20f7d710) + 16 bytes
[5] hg.dll:public: void __thiscall UITableJavaDisplayManager::CellEditCallback(class UDInterface *,class DisplayManager *,void *)(0x20f7d710, 0x20deef70, 0, 0x20954400) + 518 bytes
[6] hg.dll:public: static void __cdecl UITableJavaDisplayManager::JavaViewCellEditCallbackDispatch(class UDInterface *,class JavaViewContainer *,void *,bool)(0x20f7d710, 0x20deefac, 0x0ac8c048, 0x7aae6900) + 66 bytes
[7] hg.dll:public: virtual bool __thiscall JavaEventListener::execute(class UDEvent *)(0x00c2b584, 0x20b328a8, 0x20f7d710, 0x00c2b584) + 69 bytes
[8] udd.dll:public: bool __thiscall UDListenerList::execute(class UDEvent *)(0x00c2b584, 0x00c2b540 "dµÂ", 0x7ab0d9af, 0x06204490 "¨'²z") + 89 bytes
[9] udd.dll:public: virtual void __thiscall UDListenerManagerHost::notifyEvent(class UDDatabaseClient *,class UDEventSource const *,class UDEventInfo const *,class UDEvent *)(0x06204490 "¨'²z", 0x20f7d714, 0x20b328a8, 0x00c2b584) + 54 bytes
[10] udd.dll:public: virtual void __thiscall UDEventInfo::send(class UDDatabaseClient *,class UDInterface *,class UDEvent *)(0x06204490 "¨'²z", 0x20f7d710, 0x00c2b584, 0x20f48bc8) + 63 bytes
[11] udd.dll:public: void __thiscall UDInterface::send(class UDDatabaseClient *,class UDEventInfo *,class UDEvent *)(0x06204490 "¨'²z", 0x20b328a8, 0x00c2b584, 0) + 123 bytes
[12] udd_mi.dll:void __cdecl ProcessBeanUDDEvent(int)(290, 0, 0x00030000 "Actx ", 0x00c2b714) + 578 bytes
[13] uiw.dll:bool __cdecl UIW_DispatchUserMessage(int,int)(9226, 290, 0x00c2b714, 0x00c2b640) + 73 bytes
[14] uiw.dll:long __stdcall HandleUserMsgHook(int,unsigned int,long)(0, 1, 0x00c2b714, 9226) + 95 bytes
[15] USER32.dll:0x76cd6d80(0x00030000 "Actx ", 1, 0x00c2b714, 0x7aba74f0)
[16] USER32.dll:0x76cae1a9(0x00c2b704, 0x00c2b714, 0x00c2b730, 0)
[17] USER32.dll:0x76cb248f(0x00c2b704, 48, 0x00c2b7cc ",¸Â", 0x76ed6fa0)
[18] ntdll.dll:0x76ed6fee(0x00c2b79c, 0, 0, 0)
[19] uiw.dll:char * __cdecl getCommand(char *,int)(0x78665770, 4096, 0x00c2b838 "¬¸Â", 0x7865395f) + 362 bytes
[20] uiw.dll:public: virtual char * __thiscall uiw::UIW_IOProxy::getCmdWindowCommand(char *,int)const (0x78665770, 4096, 0, 0) + 16 bytes
[21] bridge.dll:char * __cdecl winReadStdin(char * const,unsigned int,bool)(0x78665770, 4096, 0, 0x00c2f9c8) + 79 bytes
[22] bridge.dll:char * __cdecl ioReadLineOS(bool,struct _iobuf * const,char * const,char * const,int,bool * const,void (__cdecl*const)(void),char * (__cdecl*const)(char * const,unsigned int,bool))(0, 0x72da1b78 "@IÚr", 0x205d8f48, 4096) + 265 bytes
[23] bridge.dll:char * __cdecl ioReadLine(bool,struct _iobuf *,char *,char *,int,bool *)(0, 0x72da1b78 "@IÚr", 0x205d8f48, 0x205d8f48) + 99 bytes
[24] bridge.dll:void __cdecl mnGetFullLine(char * *,unsigned int *,unsigned int *,bool)(0x00c2f9cc, 0x00c2f9c0, 0, 0x7b2b7e59) + 203 bytes
[25] bridge.dll:_mnGetCommandLineBuffer(0, 0, 0x06198520, 0) + 124 bytes
[26] bridge.dll:__catch$_mnParser$0(0x0114e2d0, 0x0dea7670, 0x00c2fa01, 0x00c2fad4 "üúÂ") + 164 bytes
[27] mcr.dll:private: void __thiscall mcrInstance::mnParser_on_interpreter_thread(void)(0x06198558, 9225, 0x00c2fb1c, 0x00c2fb2c "ÿÿÿÿxûÂ") + 51 bytes
[28] mcr.dll:public: void __thiscall boost::function0<void>::operator()(void)const (0, 0x06198520, 0, 0x06198520) + 63 bytes
[29] mcr.dll:public: virtual void __thiscall mcr::runtime::InterpreterThread::Impl::NoResultInvocationRequest::run(void)(0x79a92a60, 0x00c2fc10 "düÂ", 0x76ed6fa0, 0x00030000 "Actx ") + 53 bytes
[30] mcr.dll:private: static void __cdecl mcr::runtime::InterpreterThread::Impl::invocation_request_handler(int)(0x06198520, 0, 0x00030000 "Actx ", 0x00c2fc7c) + 40 bytes
[31] uiw.dll:bool __cdecl UIW_DispatchUserMessage(int,int)(9225, 0x06198520, 0x00c2fc7c, 0x79375e00) + 73 bytes
[32] uiw.dll:long __stdcall HandleUserMsgHook(int,unsigned int,long)(0, 1, 0x00c2fc7c, 9225) + 95 bytes
[33] USER32.dll:0x76cd6d80(0x00030000 "Actx ", 1, 0x00c2fc7c, 0x7aba74f0)
[34] USER32.dll:0x76cae1a9(0x00c2fc6c, 0x00c2fc7c, 0x00c2fc98, 0)
[35] USER32.dll:0x76cb248f(0x00c2fc6c, 48, 0x00c2fd78 "¸ýÂ", 0x76ed6fa0)
[36] ntdll.dll:0x76ed6fee(0x00c2fce8, 0, 0, 0)
[37] uiw.dll:void __cdecl UIW_GetAndDispatchMessage(struct tagMSG *)(0x00c2fce8, 9, 9, 0x06198520) + 20 bytes
[38] uiw.dll:void __cdecl UIW_GetAndDispatchMessage(void)(0x011051d0, 0, 0x01147060, 0) + 15 bytes
[39] uiw.dll:void __cdecl ws_ProcessPendingEventsMainLoop(int,bool)(1, 0, 0x00c2fd84 "ÄýÂ", 0x79a9543a) + 356 bytes
[40] uiw.dll:void __cdecl ws_ProcessPendingEvents(int,int)(1, 0xffffffff, 0x011051d0, 0x01147060) + 14 bytes
[41] mcr.dll:public: void __thiscall mcr::runtime::InterpreterThread::Impl::process_events(class boost::shared_ptr<class mcr::runtime::InterpreterThread::Impl> const &)(0x00c2fddc, 2, 0x01146c18, 0x03c3dd6c) + 138 bytes
[42] mcr.dll:__catch$?run@Impl@InterpreterThread@runtime@mcr@@QAEKABV?$shared_ptr@VImpl@InterpreterThread@runtime@mcr@@@boost@@PAUinit_context@1234@@Z$0(0x00c2fddc, 0x01147c88, 0x79a95800, 0x0114daa8) + 128 bytes
[43] mcr.dll:unsigned long __cdecl run_init_and_handle_events(void *)(0x03c3dd6c, 0, 0x01146bb8, 0) + 76 bytes
[44] mcr.dll:private: void __thiscall mcr::runtime::InterpreterThreadFactory::runThreadFunction(void)(0x00c2fe90, 0x00c2fe48, 0x00c2fe4c "¸þÂ", 0x7b299c7c) + 108 bytes
[45] matlab.exe:public: void __thiscall boost::function0<void>::operator()(void)const (1321350, 0x004077d4, 0, 0x72d11731) + 63 bytes
[46] matlab.exe:int __cdecl mcrMain(int,char const * * const)(1, 0x0114c3e0, 4194304, 1) + 230 bytes
[47] matlab.exe:_WinMain@16(4194304, 0, 1321350, 1) + 75 bytes
[48] matlab.exe:___tmainCRTStartup(0x7ffd4000, 0x00c2ffd4 "ìÿÂ", 0x76ef37f5, 0x7ffd4000) + 320 bytes
[49] kernel32.dll:0x76b03c45(0x7ffd4000, 0x61641f82, 0, 0)
[50] ntdll.dll:0x76ef37f5(0x0040324a, 0x7ffd4000, 0, 0)
[51] ntdll.dll:0x76ef37c8(0x0040324a, 0x7ffd4000, 0, 0x00905a4d)
Please follow these steps to report this problem to The MathWorks so we
have the best chance of correcting it:
The next time MATLAB is launched under typical usage, a dialog box will
open to help you send the error log to The MathWorks. Alternatively, you
can send an e-mail to segv@mathworks.com with the following file attached:
C:\Users\SNEHAP~1\AppData\Local\Temp\matlab_crash_dump.9628
If the problem is reproducible, please submit a Service Request via:
http://www.mathworks.com/support/contact_us/ts/help_request_1.html
A technical support engineer might contact you with further information.
Thank you for your help. MATLAB may attempt to recover, but even if recovery appears successful,
we recommend that you save your workspace and restart MATLAB as soon as possible.
Caught MathWorks::System::FatalException
>>
thanks..

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!