how to compare a row of the table with other rows of that table itself for the particular Columns ?
30 次查看(过去 30 天)
显示 更早的评论
Shiv Nileshkumar Matliwala
2023-1-24
编辑: Shiv Nileshkumar Matliwala
2023-5-16
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.
2 个评论
Benjamin Thompson
2023-1-24
Can you attach the sample table to this post as a MAT file and list the exact output you are looking for?
采纳的回答
Tushar Behera
2023-2-1
Hi Shiv,
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.
findgroups(yourtable.TaskPriority)
Also you can leverage functions like "ismember" and "find" which can give you row indexes for given variable value,
for example,
config=ismember(descr_table.TaskAssignment,'Separated')%group all the separated
config1=find(config==1)
%where inside config 1 you will find the row indexes
config1 =
1
2
For the complete workflow, you can refer to the following link,
I hope this resolves your query.
Regards,
Tushar
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!