Matlab read table of values

33 views (last 30 days)
sudo
sudo on 14 Aug 2022
Edited: sudo on 2 Sep 2022 at 13:01
I have a table of data. Column 1 is a building ID #. Column 2-7 are contact names. Data is entered such that the building ID# could repeat. I'm looking to pull names from column 2-7 for each building ID #. So row 1-5 maybe building 100 and row 6 and 7, are building 101. It is unknown how many rows are duplicate building #'s. In the end, i'd like to create an output for each building # that cintains all the names from column 2-7 for each row the building # was the same. Make sense?
  5 Comments
sudo
sudo on 31 Aug 2022 at 3:02
Edited: sudo on 31 Aug 2022 at 3:04
This is close. The only other item I'm wondering about is how to handle this line t(t.BuildingID==100,:) if the building ID numbers are new/unknown. So while your solution provides the output im looking for, rather than have a "hard-coded" check of each build ID how would I automate that portion? Looping through each unique buildingID.
Thanks a bunch, I think it's close.

Sign in to comment.

Answers (1)

Chunru
Chunru on 31 Aug 2022 at 1:52
Edited: Chunru on 31 Aug 2022 at 1:54
BuildingID = [100;100;100;100;100;101;101;102];
column2 = ["A";"B";"C";"D";"E";"F";"G"; ""];
t = table(BuildingID, column2, column2, 'VariableNames',{'BuildingID' 'Name' 'column3'})
t = 8×3 table
BuildingID Name column3 __________ ____ _______ 100 "A" "A" 100 "B" "B" 100 "C" "C" 100 "D" "D" 100 "E" "E" 101 "F" "F" 101 "G" "G" 102 "" ""
t.IDName = t.BuildingID+t.Name
t = 8×4 table
BuildingID Name column3 IDName __________ ____ _______ ______ 100 "A" "A" "100A" 100 "B" "B" "100B" 100 "C" "C" "100C" 100 "D" "D" "100D" 100 "E" "E" "100E" 101 "F" "F" "101F" 101 "G" "G" "101G" 102 "" "" "102"
  1 Comment
sudo
sudo on 2 Sep 2022 at 13:01
Edited: sudo on 2 Sep 2022 at 13:01
Thanks for reply. See comment above under @Lei Hou response.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!