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

답변 (1개)

Martin Lechner
Martin Lechner 2019년 11월 19일

0 개 추천

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

thank you sir for your helping
i tried your answer but when i run thr code it shows error: how can i solve it?
Error using matlab.ui.control.Table/set
Error setting property 'Data' of class 'Table':
Data must be a numeric, logical, or cell array
You will need to use a cell array. In "traditional figures" the cell array entries for the IP addresses would have to contain character vectors; it might perhaps be the case that in App Designer figures that you might be able to use a scalar string object inside the cell array.
set(P, 'data', cellstr(strings(2,1)))
The prefered solution to fill uitables is to use the Matlab's table data type. A good documentation can be found "Table Array Data Types in App Designer Apps". When you are using tables as data source for your table the column names will be automatically used as uitable column names. One further advantage is that you can directly write the table to an Excel sheet with the writetable function.
data = table(strings(2,1),'VariableNames',"IP_ADDRESS",'RowNames',["IP_CAMERA";"IP_ROBOT"])
fig = uifigure
uitable(fig,'Data',data,'ColumnEditable',true)
Walter Roberson
Walter Roberson 2019년 11월 19일
Ah, thanks, Martin.
thank you sir for these informations
unfortunately, while i'm using your code:
set(P, 'data', cellstr(strings(2,1)))
i sill can not add two dots values it shows NAN in the table here is the entire code:
app.UITable.ColumnName={'Colume_1'};
t = app.UITable;
P= app.UITable2;
P.ColumnName={'IP_ADDRESS'};
set(t,'data',ones(28,1))
set(P, 'data', cellstr(strings(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'));
please help me, how can i put like two dots value in uitable
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
regarding your second code:
data = table(strings(2,1),'VariableNames',"IP_ADDRESS",'RowNames',["IP_CAMERA";"IP_ROBOT"])
fig = uifigure
uitable(fig,'Data',data,'ColumnEditable',true)
it works, but when i add the two function READTABLE and WRITETABLE it shows error
Error using writetable (line 131)
First argument must be a table.
thanks in advance

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품

릴리스

R2018b

질문:

2019년 11월 19일

댓글:

2019년 11월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by