uitable does not accept two dot
古いコメントを表示
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
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 件のコメント
naouras saleh
2019 年 11 月 19 日
Walter Roberson
2019 年 11 月 19 日
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)))
Martin Lechner
2019 年 11 月 19 日
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
2019 年 11 月 19 日
Ah, thanks, Martin.
naouras saleh
2019 年 11 月 19 日
カテゴリ
ヘルプ センター および File Exchange で Develop Apps Using App Designer についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!