Problemas exportando datos desde uitable en Mac OS
Estimado José:
Antes que nada, muchísimas gracias por tu ayuda. He probado modificando la adquisición del dato omitiendo el str2double pero me sigue dando el mismo error, al igual que si lo hago con str2cell o num2cell.....
A continuación el código completo:
function Gui_Table (varargin)
close all
clear all
clc
panel_color=[1 1 1];
entryField_color=[0.51 0.51 0.51];
cnames = {'Item','Addition','Substraction','Division','Product'};
hFigure= figure('MenuBar','none','Units','Pixels',...
'Color','w','Toolbar','none','Name','Table model',...
'resize','off','NumberTitle','off',..................
'Position',[1 810 1280 683]);
movegui(hFigure,'center');
warning off MATLAB:uitabgroup:OldVersion % turn off warning
hg=uitabgroup('Parent',hFigure,...
'units','pixels','position',...
[1.5 10 1277 677]);
%==================================== Main Tabs =========%
ht(2)=uitab(hg,'Title','My Table');
%==================================== Main Panel =========%
hPanelB = uipanel(...
'Title','','Fontsize',22,'Parent',ht(2),.......
'Units','Pixels','BorderWidth',1,'Position',...
[1 1 1263 640],'BackgroundColor',panel_color);
%============================ Sub_Panels =============================
%## Sub Panels ##%
hSubPanel1 = uipanel('Parent',ht(2),'Units',...
'pixels','Title','Input Parameters','Fontsize',18,...
'BackgroundColor',[1 1 1],'Position',[5.5 194 595 133],...
'BorderWidth',2);
hSubPanel2 = uipanel('Parent',hPanelB,'Units',...
'pixels','Title','Main table','Fontsize',18,...
'BackgroundColor',[1 1 1],'Position',[620 70 620 350],...
'BorderWidth',2);
hSubPanel3 = uipanel('Parent',hPanelB,'Units',...
'pixels','Title','Results','Fontsize',18,...
'BackgroundColor',[1 1 1],'Position',[620 450 620 170],...
'BorderWidth',2);
%================================== Ui Table =====================
t = uitable('Parent',hSubPanel2,'ColumnName',cnames,...
'Position',[7 10 600 300],'FontSize', 14,...
'CellEditCallback',@SavePushButton_Callback);
set(t,'ColumnWidth',{114})
%================================== Input (User data) =====================
%## ID
h1label = uicontrol('Parent',hSubPanel1 ,'Units',...
'normalized','BackgroundColor',[1 1 1],'FontSize',17,...
'ForegroundColor',[0 0 0],'HorizontalAlignment','left',...
'Position',[0.06 0.70 0.17 0.14],'String','Part ID:','Style','Text');
h1Out = uicontrol('Parent',hSubPanel1 ,'Units',...
'normalized','BackgroundColor',entryField_color,'FontSize',16.5,...
'ForegroundColor',[1 1 0],'Position',[0.175 0.70 0.30 0.22],...
'String',{''},'value',0,'Style','edit');
%## Number 1
h2label = uicontrol('Parent',hSubPanel1 ,'Units',...
'normalized','BackgroundColor',[1 1 1],'FontSize',17,...
'ForegroundColor',[0 0 0],'HorizontalAlignment','left',...
'Position',[0.51 0.70 0.15 0.17],'String','Number 1:','Style','text');
h2Out = uicontrol('Parent',hSubPanel1 ,'Units',...
'normalized','BackgroundColor',entryField_color,'FontSize',16.5,...
'ForegroundColor',[1 1 0],'Position',[0.66 0.70 0.30 0.22],...
'String',{''},'value',0,'Style','edit');
%## Number 2
h3label = uicontrol('Parent',hSubPanel1 ,'Units',...
'normalized','BackgroundColor',[1 1 1],'FontSize',17,...
'ForegroundColor',[0 0 0],'HorizontalAlignment','left',...
'Position',[0.04 0.40 0.15 0.17],'String','Number 2:','Style','text');
h3Out = uicontrol('Parent',hSubPanel1 ,'Units',...
'normalized','BackgroundColor',entryField_color,'FontSize',16.5,...
'ForegroundColor',[1 1 0],'Position',[0.18 0.39 0.30 0.22],...
'String',{''},'value',0,'Style','edit');
%## Number 3
h4label = uicontrol('Parent',hSubPanel1 ,'Units',...
'normalized','BackgroundColor',[1 1 1],'FontSize',17,...
'ForegroundColor',[0 0 0],'HorizontalAlignment','left',...
'Position',[0.51 0.40 0.15 0.17],'String','Number 3:','Style','text');
h4Out = uicontrol('Parent',hSubPanel1 ,'Units',...
'normalized','BackgroundColor',entryField_color,'FontSize',16.5,...
'ForegroundColor',[1 1 0],'Position',[0.66 0.39 0.30 0.22],...
'String',{''},'value',0,'Style','edit');
%================================== Output (Analysis) =====================
%## Addition
h5label = uicontrol('Parent',hSubPanel3 ,'Units',...
'normalized','BackgroundColor',[1 1 1],'FontSize',17,...
'ForegroundColor',[0 0 0],'HorizontalAlignment','left',...
'Position',[0.01 0.65 0.15 0.17],'String','Addition:','Style','text');
h5Out = uicontrol('Parent',hSubPanel3 ,'Units',...
'normalized','BackgroundColor',entryField_color,'FontSize',16.5,...
'ForegroundColor',[1 1 0],'Position',[0.13 0.64 0.30 0.22],...
'String',{'N1+N2+N3'},'value',0,'Style','edit');
%## Substraction
h6label = uicontrol('Parent',hSubPanel3 ,'Units',...
'normalized','BackgroundColor',[1 1 1],'FontSize',17,...
'ForegroundColor',[0 0 0],'HorizontalAlignment','left',...
'Position',[0.51 0.65 0.17 0.17],'String','Substraction:','Style','text');
h6Out = uicontrol('Parent',hSubPanel3 ,'Units',...
'normalized','BackgroundColor',entryField_color,'FontSize',16.5,...
'ForegroundColor',[1 1 0],'Position',[0.69 0.64 0.30 0.22],...
'String',{'N1-N2-N3'},'value',0,'Style','edit');
%## Division
h7label = uicontrol('Parent',hSubPanel3 ,'Units',...
'normalized','BackgroundColor',[1 1 1],'FontSize',17,...
'ForegroundColor',[0 0 0],'HorizontalAlignment','left',...
'Position',[0.01 0.35 0.15 0.17],'String','Division:','Style','text');
h7Out = uicontrol('Parent',hSubPanel3 ,'Units',...
'normalized','BackgroundColor',entryField_color,'FontSize',16.5,...
'ForegroundColor',[1 1 0],'Position',[0.13 0.34 0.30 0.22],...
'String',{'N1/N2/N3'},'value',0,'Style','edit');
%## Product
h8label = uicontrol('Parent',hSubPanel3 ,'Units',...
'normalized','BackgroundColor',[1 1 1],'FontSize',17,...
'ForegroundColor',[0 0 0],'HorizontalAlignment','left',...
'Position',[0.57 0.35 0.17 0.17],'String','Product:','Style','text');
h8Out = uicontrol('Parent',hSubPanel3 ,'Units',...
'normalized','BackgroundColor',entryField_color,'FontSize',16.5,...
'ForegroundColor',[1 1 0],'Position',[0.69 0.34 0.30 0.22],...
'String',{'N1*N2*N3'},'value',0,'Style','edit');
%######## Analysis Push Buttons---
hMainPushButton = uicontrol('Parent',hSubPanel1,'Units',...
'normalized','Position',[0.78 0.01 0.22 0.18],'Style','Pushbutton',....
'String',' Run!','FontSize',20,'Callback',@MainPushButton_Callback);
hSavePushButton = uicontrol('Parent',hSubPanel3,'Units',...
'normalized','Position',[0.32 0.01 0.22 0.28],'Style','Pushbutton',....
'String',' Save!','FontSize',20,'Callback',@SavePushButton_Callback);
hResetPushButton = uicontrol('Parent',hSubPanel3,'Units',...
'normalized','Position',[0.54 0.01 0.22 0.28],'Style','Pushbutton',....
'String',' Reset!','FontSize',20,'Callback',@ResetPushButton_Callback);
hExportPushButton = uicontrol('Parent',ht(2),'Units',...
'normalized','Position',[0.85 0.01 0.12 0.08],'Style','Pushbutton',....
'String',' Export!','FontSize',20,'Callback',@ExportPushButton_Callback);
%######## Handle List ---
handle_list=...
[hFigure,hg,ht(2),hSubPanel1,...
hSubPanel2,hSubPanel3,t,h1label,h1Out,...
h2label,h2Out,h3label,h3Out,h4label,...
h4Out,h5label,h5Out,h6label,h6Out,.....
h7label,h7Out,h8label,h8Out,.....
hMainPushButton,hSavePushButton,...
hResetPushButton,hExportPushButton];
set(handle_list,'Units','normalized');
%================== EVALUATION FUNCTION BEGINS /Callbacks ============
% % --- Executes on button press in run_rad_cal.
function MainPushButton_Callback(~,~)
N1 = str2double(get(h2Out,'string')); %Number 1
N2 = str2double(get(h3Out,'string')); %Number 2
N3 = str2double(get(h4Out,'string')); %Number 3
Add = (N1 + N2 + N3);
Sub = (N1 - N2 - N3);
Div = (N1 ./ N2 ./ N3);
Pro = (N1 .* N2 .* N3);
set(h5Out,'string',num2str(Add));
set(h6Out,'string',num2str(Sub));
set(h7Out,'string',num2str(Div));
set(h8Out,'string',num2str(Pro));
%set(data{1,2},'string',num2str(Add));
end
function SavePushButton_Callback(~,~)
%%##
data{1,1}= cell2mat(get(h1Out,'string'));
data{1,2}= get(h5Out,'string');
data{1,3}= get(h6Out,'string');
data{1,4}= get(h7Out,'string');
data{1,5}= get(h8Out,'string');
oldData = get(t,'Data');
newRow = cat(0,data,cell(0,size(data,2)));
newData2 = [oldData; newRow];
set(t,'Data',newData2);
backgroundColor = [.5 .41 .21; .31 .45 .64];
% Table Background color
set(t, 'BackgroundColor', backgroundColor);
set(t, 'ColumnEditable', [true false false false]);
end
function ResetPushButton_Callback(~,~)
set(t,'Data',[])
set(t,'Rowname',[]);
end
function ExportPushButton_Callback(~,~)
d = str2double(get(t,'Data'));
header = cnames;
cellVals = [header;num2cell(d)];
fh = fopen('G.csv','w');
for ii = 1:size(cellVals,1)
first = 1;
for jj = 1:size(cellVals,2)
if first
fwrite(fh,num2str(cellVals{ii,jj}));
first = 0;
else
fwrite(fh,[',',num2str(cellVals{ii,jj})]);
end
end
fwrite(fh,sprintf('\r\n'));
end
fclose(fh);
end
end