Separate and Operate on Cells Based on Label

Hello,
I need assistance with separating out a cell array consisting of text labels within each cell based on the label. I have tried the findgroups function, but I would like to have the labels remain for further operations instead of the generated numbers for the labels (for example, I'd want to work with group "bicep" instead of group "1"). If I am misunderstanding how findgroups works and that is a possible outcome with that function, please explain how, as I am still new to Matlab.
Secondly, once those cells are separated based on the label, I need some way to go through all of the groups separately with a function (in this case, a mean of the unique values in corresponding cells). I understand how to do the function if all values were in the same group, but I am confused if working with numerous groups at the same time.
If there's anything else needed to help with my case, please ask and I can give more information. Thank you. (see comments)

6 Comments

Your question is not precise.
1. Given varying and repeating text labels in the cells of a 1xN cell array, how do you group the cells based on the labels? Preferably by still keeping the labels instead of changing them to something else (like a number reference).
2. How do you apply a function (like unique) to separated groups at the same time so as not to have to do it individually for each group?
Is that better?
Could you provide a tiny example of input and required output.
Have you thought of using Create and Work with Tables? (Introduced in R2013b)
Ex. Run program with file; gives 2 outputs: a Legend for the Objects and the Objects
Legend = [Biceps, Triceps, Forearm, Chest, Deltoid]
ObjectLabels = [Biceps, Deltoids, Biceps, Chest, Chest, Forearm, Forearm, Triceps]
ObjectXposition = [1,3,2,3,1,4,2,3]
ObjectYposition = [1,3,2,3,1,4,2,3]
ObjectZposition = [1,3,2,3,1,4,2,3]
So I need to plot the Objects separately based on their label while keeping the cell so that the corresponding values can also be used. Something like:
Biceps Locations Deltoid Loc. Chest Loc.
[Biceps, Biceps] [Deltoid] [Chest, Chest]
[1,2] [3] [3,1]
[1,2] [3] [3,1]
[1,2] [3] [3,1]
I already know how to plot such a setup, so how can I separate/sort the list of labels? I believe that connecting it to the Legend would be easiest, but I am unsure how to do that.
"I'd want to work with group "bicep" instead of group "1"" &nbsp means that you you want to use statements like
plot( ..., 'bicep' )
How large is the total dataset, typically?
It can vary depending on how much data is given. Currently working with around 14 labels. A way to group the data such that naming each individual label during plotting would be unnecessary would be nice, if possible. Along the idea that the groups are separated, but still remain under a variable LABELS or something like that, so plot(Labels) would go through each group individually and plot them without having to name them. If that's not a possibility, it can be worked around.

Sign in to comment.

Answers (1)

Try the ismember() function. To get the means, you can use grpstats().

3 Comments

So this is the idea that I am looking for (checking one list for corresponding values from another list), but it seems like the ismember() only gives a true/false for if any repetitions at all are there instead of giving a means to separate the corresponding values. Am I mistaken in the ismember() capabilities or is there another way to do that?
Stephen23
Stephen23 on 11 Jul 2016
Edited: Stephen23 on 11 Jul 2016
Have a look at ismember's second output. You could use that output in accumarray to group/process your data together.
Using the Lia or Lia,Locb function requires a string instead of cells, which doesn't work due to the long list of text that ends up in a single cell. I cannot seem to find the members when all of them are together in the same cell. Possibly text was not intended for the ismember() function.

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Asked:

on 8 Jul 2016

Commented:

on 12 Jul 2016

Community Treasure Hunt

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

Start Hunting!