Matlab read table of values

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 件のコメント

Matt J
Matt J 2022 年 8 月 14 日
How would the output be different from the table that you already have?
sudo
sudo 2022 年 8 月 14 日
編集済み: Walter Roberson 2022 年 8 月 15 日
The output wouldn't contain all building #'s. Instead of one table with all building #'s and names (like i started with), I would have a table per building #. In essence creating several csv or text files instead of what I am starting with which is one that contains entries of multiple building #'s and sometimes new building #'s exist as well as new names per building #.
Example
B# N1 N2 N3 N4 N5 N6
0 Jd1 Jd2 Jd3 Jd4 Jd5 Jd6
0 Jd7 Jd8 JD9 JD10 Jd11 jd12
0...( could be several more)
52 To1 To2 To3 To4 To5 To6
52...(could be several more)
58..(names could be blank)
58..
63 Jd1 Jd2 Jd3 Jd5
63 Jd7 JD9
63......
Hope that helps sort of visually see the input file without posting it.
sudo
sudo 2022 年 8 月 16 日
Anyone have some direction or guidance on approach for this one or is the description of the problem not clear enough? Thanks
Lei Hou
Lei Hou 2022 年 8 月 31 日
Hi Sudo,
Does the following solution solve your problem?
>> BuildingID = [100;100;100;100;100;101;101];
>> column2 = ["A";"B";"C";"D";"E";"F";"G"];
>> t = table(BuildingID, column2, column2, column2, column2, column2, column2, 'VariableNames',{'BuildingID' 'column2' 'column3' 'column4' 'column5' 'column6' 'column7'})
t =
7×7 table
BuildingID column2 column3 column4 column5 column6 column7
__________ _______ _______ _______ _______ _______ _______
100 "A" "A" "A" "A" "A" "A"
100 "B" "B" "B" "B" "B" "B"
100 "C" "C" "C" "C" "C" "C"
100 "D" "D" "D" "D" "D" "D"
100 "E" "E" "E" "E" "E" "E"
101 "F" "F" "F" "F" "F" "F"
101 "G" "G" "G" "G" "G" "G"
>> t(t.BuildingID==100,:)
ans =
5×7 table
BuildingID column2 column3 column4 column5 column6 column7
__________ _______ _______ _______ _______ _______ _______
100 "A" "A" "A" "A" "A" "A"
100 "B" "B" "B" "B" "B" "B"
100 "C" "C" "C" "C" "C" "C"
100 "D" "D" "D" "D" "D" "D"
100 "E" "E" "E" "E" "E" "E"
>> t(t.BuildingID==101,:)
ans =
2×7 table
BuildingID column2 column3 column4 column5 column6 column7
__________ _______ _______ _______ _______ _______ _______
101 "F" "F" "F" "F" "F" "F"
101 "G" "G" "G" "G" "G" "G"
sudo
sudo 2022 年 8 月 31 日
編集済み: sudo 2022 年 8 月 31 日
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.

サインインしてコメントする。

回答 (1 件)

Chunru
Chunru 2022 年 8 月 31 日
編集済み: Chunru 2022 年 8 月 31 日

0 投票

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 件のコメント

sudo
sudo 2022 年 9 月 2 日
編集済み: sudo 2022 年 9 月 2 日
Thanks for reply. See comment above under @Lei Hou response.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeTables についてさらに検索

質問済み:

2022 年 8 月 14 日

編集済み:

2022 年 9 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by