Connecting matrix values with fields in a structure
1 view (last 30 days)
Show older comments
Hi, I am trying to write a code that matches certain values in a matrix with their corresponding fields when I load in the data.I have an nx3 matrix where the first column is a number grouping the objects in the second and third columns, and the second and third columns are IDs of objects that I want to match to the fields. So my matrix right now is something like
1 100 100
1 100 101
1 100 102
2 100 100
2 100 101
3 101 100
3 101 101
3 101 102
3 101 103
4 101 100
I am trying to match the IDs in columns 2 and 3 with their corresponding structures S and T respectively, while still keeping the objects together within their group. The objects in the structures S and T are the fields and can be accessed by S.(nms{i}) and T.(names{ii}) where i and ii are the indices of the fields and the names of the fields are nms and names respectively. I want the IDs to correspond to the fields in that 100 = S.(nms{1}) for group 1 (so column 2 rows 1:3) and then 100 = S.(nms{2}) for group 2 (column 2 rows 4 and 5). Then for column 3, 100 = T.(names{1}) for group 1, 101 = T.(names{2}) for group 1 and then 100 = T.(names{4}) for group 2 and so on.
My intention is so that I can run some other code on the objects in the structures for each group. Right now, I have to run my code separately for each group, but I would like to be able to run the code once and have it iterate the code for each group for me. Any help would be appreciated!
0 Comments
Answers (0)
See Also
Categories
Find more on Data Import and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!