randperm function for a table – keep rows together
I looked in help but everone seems to be randomizing a vector.
The closest ask I can find is
https://www.mathworks.com/matlabcentral/answers/155207-matrix-with-different-randperm-rows?s_tid=sug_su
I have a table (including a category column) I asked (Q )about using Shuffle but if that doesn’t handle table shuffling like I need i can take the performance hit and use randperm()
Here’s what I’m doing:
app.TrialsTable = table(‘Size’,[2*C 4],’VariableTypes’,{‘uint8′,’uint8′,’categorical’,’int16′});
… % fill the table from given input table, expanding rows as needed for number of repeats
app.TrialsTable(index, 1) = … %and so on
…
app.TrialsTable = Shuffle(app.TrialsTable, ???); % if anyone knows how to do it this way
& or
app.TrialsTable(randperm(height(app.TrialsTable(:,:)))); % How do I make this line work??
% and then finally
set(app.RandTrialsTable,’Data’,app.TrialsTable(:,:)); % save it to the UITable for display in the Figure
Testing at the command prompt for various options of randperm(…)
app.TrialsTable(randperm(height(app.TrialsTable(:,:))))
Error using ()
Subscripting into a table using one subscript (as in t(i)) is not supported. Specify
a row subscript and a variable subscript, as in t(rows,vars). To select variables,
use t(:,i) or for one variable t.(i). To select rows, use t(i,:).
I didn’t use 1 subscript so the Error message doesn’t help
Another try:
app.TrialsTable(:,:)(randperm(height(app.TrialsTable(:,:))))
Error: Invalid array indexing.
Test
(randperm(height(app.TrialsTable(:,:))))
ans =
Columns 1 through 14
17 18 13 8 3 9 19 27 14 6 25 15 2 5
Columns 15 through 28
7 23 24 12 22 20 28 21 26 4 16 1 10 11
I only have 4 columns (28 rows)
Try
(randperm(height(app.TrialsTable)))
ans =
Columns 1 through 14
27 14 22 4 10 2 21 3 5 15 18 28 23 7
Columns 15 through 28
24 16 25 9 6 13 26 17 19 20 1 11 8 12
No sign of the category column (‘L’ or ‘R’) sorting along with it.
OH! maybe I don’t need to tell the height (as the Shuffle guy said)
(randperm(app.TrialsTable))
Error using randperm
Conversion to double from table is not possible.
try
(randperm(app.TrialsTable(:,:)))
Error using randperm
Conversion to double from table is not possible.
randperm(1:size(app.TrialsTable.Row))
ans =
1×0 empty double row vector
I tried on my own, time to ask for help!I looked in help but everone seems to be randomizing a vector.
The closest ask I can find is
https://www.mathworks.com/matlabcentral/answers/155207-matrix-with-different-randperm-rows?s_tid=sug_su
I have a table (including a category column) I asked (Q )about using Shuffle but if that doesn’t handle table shuffling like I need i can take the performance hit and use randperm()
Here’s what I’m doing:
app.TrialsTable = table(‘Size’,[2*C 4],’VariableTypes’,{‘uint8′,’uint8′,’categorical’,’int16′});
… % fill the table from given input table, expanding rows as needed for number of repeats
app.TrialsTable(index, 1) = … %and so on
…
app.TrialsTable = Shuffle(app.TrialsTable, ???); % if anyone knows how to do it this way
& or
app.TrialsTable(randperm(height(app.TrialsTable(:,:)))); % How do I make this line work??
% and then finally
set(app.RandTrialsTable,’Data’,app.TrialsTable(:,:)); % save it to the UITable for display in the Figure
Testing at the command prompt for various options of randperm(…)
app.TrialsTable(randperm(height(app.TrialsTable(:,:))))
Error using ()
Subscripting into a table using one subscript (as in t(i)) is not supported. Specify
a row subscript and a variable subscript, as in t(rows,vars). To select variables,
use t(:,i) or for one variable t.(i). To select rows, use t(i,:).
I didn’t use 1 subscript so the Error message doesn’t help
Another try:
app.TrialsTable(:,:)(randperm(height(app.TrialsTable(:,:))))
Error: Invalid array indexing.
Test
(randperm(height(app.TrialsTable(:,:))))
ans =
Columns 1 through 14
17 18 13 8 3 9 19 27 14 6 25 15 2 5
Columns 15 through 28
7 23 24 12 22 20 28 21 26 4 16 1 10 11
I only have 4 columns (28 rows)
Try
(randperm(height(app.TrialsTable)))
ans =
Columns 1 through 14
27 14 22 4 10 2 21 3 5 15 18 28 23 7
Columns 15 through 28
24 16 25 9 6 13 26 17 19 20 1 11 8 12
No sign of the category column (‘L’ or ‘R’) sorting along with it.
OH! maybe I don’t need to tell the height (as the Shuffle guy said)
(randperm(app.TrialsTable))
Error using randperm
Conversion to double from table is not possible.
try
(randperm(app.TrialsTable(:,:)))
Error using randperm
Conversion to double from table is not possible.
randperm(1:size(app.TrialsTable.Row))
ans =
1×0 empty double row vector
I tried on my own, time to ask for help! I looked in help but everone seems to be randomizing a vector.
The closest ask I can find is
https://www.mathworks.com/matlabcentral/answers/155207-matrix-with-different-randperm-rows?s_tid=sug_su
I have a table (including a category column) I asked (Q )about using Shuffle but if that doesn’t handle table shuffling like I need i can take the performance hit and use randperm()
Here’s what I’m doing:
app.TrialsTable = table(‘Size’,[2*C 4],’VariableTypes’,{‘uint8′,’uint8′,’categorical’,’int16′});
… % fill the table from given input table, expanding rows as needed for number of repeats
app.TrialsTable(index, 1) = … %and so on
…
app.TrialsTable = Shuffle(app.TrialsTable, ???); % if anyone knows how to do it this way
& or
app.TrialsTable(randperm(height(app.TrialsTable(:,:)))); % How do I make this line work??
% and then finally
set(app.RandTrialsTable,’Data’,app.TrialsTable(:,:)); % save it to the UITable for display in the Figure
Testing at the command prompt for various options of randperm(…)
app.TrialsTable(randperm(height(app.TrialsTable(:,:))))
Error using ()
Subscripting into a table using one subscript (as in t(i)) is not supported. Specify
a row subscript and a variable subscript, as in t(rows,vars). To select variables,
use t(:,i) or for one variable t.(i). To select rows, use t(i,:).
I didn’t use 1 subscript so the Error message doesn’t help
Another try:
app.TrialsTable(:,:)(randperm(height(app.TrialsTable(:,:))))
Error: Invalid array indexing.
Test
(randperm(height(app.TrialsTable(:,:))))
ans =
Columns 1 through 14
17 18 13 8 3 9 19 27 14 6 25 15 2 5
Columns 15 through 28
7 23 24 12 22 20 28 21 26 4 16 1 10 11
I only have 4 columns (28 rows)
Try
(randperm(height(app.TrialsTable)))
ans =
Columns 1 through 14
27 14 22 4 10 2 21 3 5 15 18 28 23 7
Columns 15 through 28
24 16 25 9 6 13 26 17 19 20 1 11 8 12
No sign of the category column (‘L’ or ‘R’) sorting along with it.
OH! maybe I don’t need to tell the height (as the Shuffle guy said)
(randperm(app.TrialsTable))
Error using randperm
Conversion to double from table is not possible.
try
(randperm(app.TrialsTable(:,:)))
Error using randperm
Conversion to double from table is not possible.
randperm(1:size(app.TrialsTable.Row))
ans =
1×0 empty double row vector
I tried on my own, time to ask for help! shuffling a table MATLAB Answers — New Questions