uitable does not accept two dot
2 次查看(过去 30 天)
显示 更早的评论
hello,
i'm new to the matlab (uitable). i'm writing a code with two uitable and i want to read from excel file and then edit in the table then write to excel file the new data . every things are working except i can't write a number in the uitable like this '192.168.210.230' (WITH TWO DOTS ) how can i make the uitable accept this kind of value like ip address?
here is my code:
function startupFcn(app)
app.UITable.ColumnName={'Colume_1'};
t = app.UITable;
P= app.UITable2;
P.ColumnName={'IP_ADDRESS'};
set(t,'data',ones(28,1))
set(P,'data',ones(2,1))
app.UITable.RowName={'z1';'z2';'z3';'z4';'z5';'z6';'z7';'z8';'z9';'z10';'z11';'z12';...
'z13';'z14';'z15';'z16';'z17';'z18';'z19';'z20';'z21';'z22';'z23';'z24';'z25';'u';'v';'w' };
P.RowName={'IP_CAMERA';'IP_ROBOT'};
set(t,'ColumnWidth',{200})
set(t,'ColumnEditable',logical([1]))
set(P,'ColumnWidth',{500})
set(P,'ColumnEditable',logical([1]))
t.Data(:,1) = 0;
P.Data(:,1) = ' ';
t.Data= xlsread('sos.xlsx',('A1:A28'));
P.Data= xlsread('sos.xlsx',('B1:B2'));
and for push button in order to save the new data :
function pushtosaveButtonPushed(app, event)
t = app.UITable;
P= app.UITable2;
l= get(t, 'data');
f=get(P, 'data');
xlswrite('sos.xlsx', l,('A1:A28'))
xlswrite('sos.xlsx', f,('B1:B2'))
end
end
0 个评论
回答(1 个)
Martin Lechner
2019-11-19
So that your IP-address can contain 2 dots, you must use a string data type for your IP-address column (initialize it with strings(2,1) instead of ones(2,1).
Replace
set(P,'data',ones(2,1))
by
set(P,'data',strings(2,1))
5 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!