Create comma-separated list from data of UITable

조회 수: 4(최근 30일)
Beth Carreon
Beth Carreon 2022년 5월 14일
댓글: Beth Carreon 2022년 5월 21일
I want to create a list of latitude just like the format below from a UITable
latitudes = [lat1, lat2, lat3,...];
This is the data from the UITable.
I am getting this result using the following code, clearly with no commas.
m = horzcat(app.UITable.Data{:,3})
m =
'13.9524380813.9524398613.95226986 13.9475104713.94693600'
Does anyone know how to do this? Thanks
  댓글 수: 3
dpb 2022년 5월 14일
See the expected, this can be simplified greatly by proper use of data types and storage.

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

채택된 답변

dpb 2022년 5월 14일
편집: dpb 2022년 5월 14일
>> which -all kmlwritepoint
'kmlwritepoint' not found.
So this is not a MATLAB function I've got... kmlwritepoint shows it in the Mapping TB so that 'splains that.
But that very same document shows (and the error reinforces) that the input it expects is just the numeric (double) vector array.
The suggestion to set the data columns to be numeric to ensure they are and then simply
names = {'1', '2', '3'};
filename = 'test.kml';
kmlwritepoint(filename, app.UITable.Data{:,2}, app.UITable.Data{:,3}, 'Name', names);
wlll be the expected syntax.
BUT -- If you would store your data in a MATLAB table and use uitable to display it to the user in the GUI, then you could retrieve the data from it directly as the table and even use the column headers -- here's an example taken from the above doc link -- I just renamed the two variables to match yours for to have some data.
Try this for grins...
t = readtable('patients.xls'); % the uitable example dataset
vars = {'Systolic','Diastolic'}; % we just want two variables
tCoords=t(1:10,vars); % and only need a few to illustrate
tCoords.Properties.VariableNames={'Latitude','Longitude'}; % pretend they're coordinates instead...
hUF=uifigure; % make a uifigure
hUIT=uitable(hUF,'Data',tCoords); % display the table
That created the following plain vanilla figure...
Now play with that some at command line...
>> hUIT.Data
ans =
10×2 table
Latitude Longitude
________ _________
124.00 93.00
109.00 77.00
125.00 83.00
117.00 75.00
122.00 80.00
121.00 70.00
130.00 88.00
115.00 82.00
115.00 78.00
118.00 86.00
Observe we got the table back as a table -- much more convenient than having to deal with the string representation...
With this you can also write
>> hUIT.Data.Latitude
ans =
so your call to write the data out can be reduced to
names = {'1', '2', '3'};
filename = 'test.kml';
kmlwritepoint(filename, hUIT.Data.Latitude,hUIT.Data.Longitude, 'Name', names);
which is "much more simpler" and legible to read the code, besides.
If you're not using a table to store your data in the app, you should be! :)
NB: I don't know what the three Names are supposed to match up to here; I'm guessing that may have something to do with there being the first unshown column in the table. Would need more info to know just what to do there, not having any experience with the Mapping TB and hence "knowing nuthink!" about just what kmlwritepoint is doing.
  댓글 수: 8
Beth Carreon
Beth Carreon 2022년 5월 21일
Hello @dpb, I was able to finish my project because of your help, thank you very much!

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

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by