Applying a function only to certain rows in a table, marked by the start of the name.

1 Ansicht (letzte 30 Tage)
Hi and Hello,
I am currently working on a big set of data that is saved in a table.
The First collum is the Name of the Individual rows like "AB12_345678", AC12_345678
The rest of the collums contain different values. (doubles and numbers)
I am trying to figure out how to apply a function like mean or max only to those rows, thats name start with e.g "AB1".
I had no success with substrings, startsWith or rowfunc.
I am truly lost on how to do this since i want to avoid selecting the data by hand and running the code like 75 times.
Any and all help would be appreaciated.
Thanks in advance!

Akzeptierte Antwort

Saurabh
Saurabh am 6 Jun. 2023
you can use the startsWith function from the Text Analytics Toolbox to select the rows of a table whose name starts with a certain keyword.
And then accordingly You can access the rest of the values if you have the idices of the Table, thats name start with e.g "AB1".
Let me Know if this works.
startStr = "AB1";
idx = startsWith(string(file_name.PropertyName), startStr);
  2 Kommentare
VeHe
VeHe am 6 Jun. 2023
Hi Saurabh,
it returned which Rows contain the string, so it wasn't quiet what I needed
But I looked at startsWith again and got this
TAB1 = Table(startsWith(Table.Column,'AB1'),:);
The codeline does create another table which might not be the most elegant way to do this, but like this I can apply the functions i need to the subsets
Thank you for your time and input!
Saurabh
Saurabh am 6 Jun. 2023
You are Welcome, if possible can you mark upvote/accept the solution.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by