help for loading an empty excel sheet in matalb gui table
1 view (last 30 days)
Show older comments
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);
0 Comments
Answers (2)
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?
0 Comments
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!