Export Table from Matlab Guide to Excel
显示 更早的评论
Hello everyone!
I am having serious trouble trying to export a TABLE from MATLAB GUIDE to EXCEL with a PUSH BUTTON.
How would I go about coding this exactly under a push button?
And under which function would I code this under?
Thank you very much for your help!
12 个评论
darova
2020-3-26
What about xlswrite?
See writetable, writematrix, or writecell. xlswrite is not recommended unless you're working with an older release of Matlab prior to when these other functions became available.
-----------------------------------------------------------------------------------------------------------
Copy of question:
Hello everyone!
I am having serious trouble trying to export a TABLE from MATLAB GUIDE to EXCEL with a PUSH BUTTON.
Here is my code below for my table:
function save_table_OpeningFcn(hObject, eventdata, handles, varargin)
global t
t.MyData = [];
handles.output = hObject;
guidata(hObject, handles);
% --- Executes on button press in fillin.
function fillin_Callback(hObject, eventdata, handles)
global t
Level5 = get(handles.Level5, 'string');
Level6 = get(handles.Level6, 'string');
t.MyData = [t.MyData ; [{Level5} {Level6}]];
set(handles.table1, 'Data', t.MyData)
% --- Executes on button press in Save.
function save_Callback(hObject, eventdata, handles)
How would I go about coding this exactly under a push button?
And under which function would I code this under?
Adam Danz
2020-3-26
In GUIDE GUIs, handles.uitable1.Data returns a cell array. Try the writecell function . If your data are all numeric, you could convert the cell array to a matrix and use writematrix.
Guillaume
2020-3-26
"i tried this but it doesn't work"
...is a useless statement without more details. We can't see your computer! If you get an error give us the full text of the error message. If you get a different result than you expected then explain what you got and how it differs from what you wanted.
Adam Danz
2020-3-26
Is that the full error message?
It looks like the error is caused by another part of your callback function or the callback function definition itself. My guess is that the inputs to save_table are incorrect.
If this isn't the entire error message (no matter how long it is), please share it.
Is save_table a callback function or a function you wrote within the GUI?
"Yes that is the full error message.
And no, the error is not caused by another part of my callback.
Everything was working fine before I put in that code- no error no nothing! "
Error in save_table (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)save_table('fillin_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
I'm having trouble accepting that this is the entire error message. Could you clear your command window using clc and run the GUI again so it produces the error message and copy-paste everything from the command window into a new comment?
If you're correct that xlswrite is causing the error, then I'm 100% certain that this isn't the full error message.
Based on the what we've got, it appears that save_table is the name of your GUI and fillin_Callback is the name of a callback function. The error is happening within that callback function.
Miss B
2020-3-26
darova
2020-3-26
Feel sorry for Adam ;(
darova
2020-3-26
i just want someone to pay me
I want 2000 reputation points
Adam Danz
2020-3-27
@Miss B, please understand why it was important to confirm that the entire error message was shared because this will help you troubleshoot in the future. Below is a typical, complete error message produced from within a GUIDE GUI named save_table. The error message you shared only contained the last 5 lines but critical information is in the first few lines which seemed to have been missing from the error message you shared.
Also notice that the error message you shared doesn't mention xlswrite at all. So, it must be the case that either 1) the error wasn't caused by xlswrite or 2) parts of the error message was missing. Or, maybe you resolved that error on your own and were having a different problem that wasn't communicated effectively.
We can't suggest solutions before we understand the problem and I know it's often difficult to explain the problem (it's like me describing the sounds my car's making to the mechanic).
Not enough input arguments. % <-- %
Error in save_table>pushbutton1_Callback (line 85) % <-- This part seems %
cla(handles.axes1) % <-- to be missing %
Error in gui_mainfcn (line 95) % <-- from your error %
feval(varargin{:}); % <-- message. %
Error in save_table (line 19)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)save_table('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Tables 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!