MATLAB Answers

uitable does not accept two dot

4 views (last 30 days)
naouras saleh
naouras saleh on 19 Nov 2019
Commented: naouras saleh on 19 Nov 2019
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

Answers (1)

Martin Lechner
Martin Lechner on 19 Nov 2019
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 Comments
naouras saleh
naouras saleh on 19 Nov 2019
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

Sign in to comment.

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!