필터 지우기
필터 지우기

uitable does not accept two dot

조회 수: 1 (최근 30일)
naouras saleh
naouras saleh 2019년 11월 19일
댓글: naouras saleh 2019년 11월 19일
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일
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
Walter Roberson
Walter Roberson 2019년 11월 19일
Ah, thanks, Martin.
naouras saleh
naouras saleh 2019년 11월 19일
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

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

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by