I have a table as below : (This is a few lines from my table)
T = table({'A';'A';'A';'B';'B';'B';'C';'C';'C';'C'}, {'x';'y';'z';'x';'w';'t';'z';'x';'t';'o'},[5;1;2;2;4;2;2;5;4;1], ...
'VariableNames', {'memberId', 'productId','Rating'});
T:
A x 5
A y 1
Z z 2
B x 2
B w 4
B t 2
C z 2
C x 5
C t 4
C o 1
C u 3
D r 1
D t 2
D w 5
.
.
.
.
I need to take the user A then Create a table like Previous table (Table T) and All rows are related to the user A to enter that table.At this point in the table are the following lines:
A x 5
A y 1
A z 2
Next, consider products related to this user i.e x,y,z . then All lines that contain x and then y and z are adding to the table. At this point in the table are the following lines:
A x 5
A y 1
A z 2
B x 2
C z 2
C x 5
Then, other users have been added to the table to consider i.e B,C . Then The same thing was done for the first user (A) is done for this user (Respectively for B then C). This is done so that the required number of rows add in the table. Here, for example, 8 rows is required. i.e The end result is as follows:
A x 5
A y 1
A z 2
B x 2
C z 2
C x 5
B w 4
B t 2
i.e when work is finished the requested number of rows in the second table row to be imported.
I would be grateful if any body help me in this regard.
Here is a way for doing what you ask for (though some cases are not well defined in your question):
Which gives
newT
:In this implementation, the rows are added user by user, and product by product, and if the next user/product to be added has more rows then what's available in
newT
, then we add as much rows as we cen, until we get to therows_limit
and then the loop quits.So for a
rows_limit = 4;
, you will getnewT
as:As long as there are connections between users, so each user's related products brings new users to the list, the loop continues with the new users in
newT
. However, it could be that we start from a node that not all other nodes are parts of its network. For instance, have a look a the following graph figure that illustrates the connections in the extended example I used in the code above:Node
D
is not connected to all others, so unless we actively look for new unrelated users inT
, we will never get to it. The implementation above does look for this kind of users.