Accessing all data in a matrix dimension via a custom label.

1 Ansicht (letzte 30 Tage)
Parker Wray
Parker Wray am 4 Jul. 2020
Kommentiert: Sindar am 5 Jul. 2020
Hello,
I would like to access data across a dimension according to a custom label for that dimension. To give a simple example, assume I have a matrix that records patient blood pressure (BP) based on patient height, weight, age, gender, race, and ethnicity. I now want to add a new age to the age dimension in my data (assume I have 4 unique ages and I want to add data for a new 5th age). Currently, this requires me to do BP(:, : , 5, :, :, :) = [new data];. This process is very annoying for large matricies. I'm constantly having to remember which dimension maps to what identifier and I am constantly counting/debugging the number of ":". Is there a more elegant and intuitive way to perform this operation? Idealy I would like to be able to access data through a text identifier (e.g., something like add(BP, [new data], "age") ). Likewise, it would be nice to grab cross sections in this data as well (e.g., [3rd age cross section] = cross_section(BP, "age", 3)).
P.s., I do not believe structures can solve this problem since each field of a structure is uniquely different. I also do not believe a table would work, since tables are limited to 2D.
Thank you all, in advance, for the help!
  2 Kommentare
Walter Roberson
Walter Roberson am 5 Jul. 2020
Bearbeitet: Walter Roberson am 5 Jul. 2020
You can repmat({':'},1, number_of_dimensions) and the replace an entry of that with the indexing information, then do cell expansion on that as the indexing information for the array. This is not elegant or intuitive by itself, but it does permit you to write little helper functions
Sindar
Sindar am 5 Jul. 2020
Out of curiousity, is your data densely-populated? It seems like your 6-dimensional array would have a lot of unknown elements. If that's the case, it may be better to use a table with columns for each identifier and then one for the data. I'm not too familiar with Matlab tables, but there are ways to pull the data out based on identifiers and you could probably easily write helper functions

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by