how to compare a row of the table with other rows of that table itself for the particular Columns ?
6 views (last 30 days)
Show older comments
Shiv Nileshkumar Matliwala on 24 Jan 2023
Answered: Tushar Behera on 1 Feb 2023
Suppose I have a table as below,
Now, in the above table first I want to check the TaskAssignment value. If it is 'Separated' then I want to store the Index value of that row into one array for example in above as an output i need to store index value 1 and 2 in an array called 'Configure1'
Now after checking the TaskAssignment, I want to focus now only on TaskAssignment = 'Summarized' rows.
Here, now first I need to check the TaskPriority for that all fours rows who has value TaskAssignment = 'Summarized', if there more than one TaskPriority which is the case above, I need to make group of that rows. so there will be two groups of TaskPriority '30' and '31' and now I want to check the 'EventType' value for these groups one by one. and if that values are equal which is the case above then I want check for the 'Period' value of that group rows. If both 'EventType' and 'Period' for the group of TaskPriority = '30' then I want to store index of that rows in one variable 'Group' and then stored the same index value which is 4 and 6 to 'Configure2' array.
Now if there are two rows in one group then if any value of 'EventType' and 'Period' of those two rows are different then I need to concatanet those row's index value for example 4 and 6 to 'Configure1'
if there are more than two rows in one group then the row which has the different value for 'EventType' and 'Period' compare to two other rows with same value then again I want to add the Index value of that row to 'Configure1' and all the other rows who has same values, thier index values will go to 'Configure2'
It is actually a bit complicated. I hope you have understood what i am trying to explain here.
Tushar Behera on 1 Feb 2023
I believe what you are looking for is first to group your data according to "TaskAssignment" and then for "TaskAssignment" which has the value "Summarized" you want to group them based on "TaskPriority" and eventually group them based on "EventType" and "Period". Given that "EventType" and "Period" should e looked upon simultaneously. After which you want their row indexes in two separate arrays.
This can be achieved by using functions such as "findgroups", this will give you an array of group indexes that are equal in value.
Also you can leverage functions like "ismember" and "find" which can give you row indexes for given variable value,
config=ismember(descr_table.TaskAssignment,'Separated')%group all the separated
%where inside config 1 you will find the row indexes
For the complete workflow, you can refer to the following link,
I hope this resolves your query.
Find more on Introduction to Installation and Licensing 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!