Matrix manipulation - smarter way to do this?

So,
1st column has trials from 1:300 but for each of the values there are multiple rows (this are samples in time - msecs)..
2nd column has conditions from 1:25.
See attached sample.txt
Each of the trials in column 1 is associated with a single value from column 2. Obviously multiple trials share the same conditions.
What I want is this:
1) Group conditions into eg. [2 5 7 10 ] or [1 4 5 6 7] etc.. I.e. any combination of conditions.
2) Group the corresponding trial data (Columns 3 to 10) separately. i.e. Column 3 from all the trials(1:300) that fall under Condition Group 1 should now become 1 matrix ordered in time.These should just stack on top of each other. I.e. same number of samples from each trial.
See attached Column5.txt (in this example trials 1 and 2 belonged to condition 5)

3 Commenti

doc ismember
doc intersect % and friends
As said in response a day or two ago, look to the data object if have the Statistics Toolbox (never said yes/no)
doc accumarray
is useful with the above selection functions to build index vectors to fill arrays with results therefrom. Or, for single answers or for simply selecting subsets, look up 'logical addressing' in the documentation for how to address subsets of arrays based on conditional tests.
I suggest creating a much smaller sample of data as input and an example of the expected output and simply paste it into the window. 10 or even fewer lines should be plenty to illustrate the desire more simply than trying to parse the verbiage.
yes, I have statistics toolbox..did you see attached sample.txt(eg. sample input) and Column5.txt(eg. desired result)?

Risposte (1)

Build the vector G(K) such that K is a condition number and G(K) is the number of the condition group it is to be placed in. Then G(column2) tells you which matrix number to toss each line into.
for T = 1 : size(YourData,1)
Matrices{G(YourData(T,2))}(end+1,:) = YourData(T,3:end);
end

6 Commenti

Sorry, I don't understand.. This looks simple but I'm having troule.
If you have the patience, would you mind explaining?
Groups{1} = [2 5 7 10 ];
Group{2} = [1 4 5 6 12];
Group{3} = [3 8 9 11 13:25];
G = zeros(25,1);
for GroupNum = 1 : length(Groups)
thisgroup = Groups{GroupNum};
for K = 1 : length(thisgroup)
G(K) = GroupNum;
end
end
After this, G will be a vector of length 25, that maps from condition number to group number. Once that mapping exists, it becomes efficient to figure out which matrix should be updated, with no searching required.
Hi! Unfortunately I don't think this will work..
Let me try to explain more clearly.
1 5 80 391 30 181 00
1 5 70 391 30 181 00
2 1 70 391 30 181 00
2 1 60 391 40 181 00
3 5 50 391 40 181 00
3 5 40 391 40 181 00
4 3 40 391 40 181 00
4 3 40 391 40 181 00
5 4 50 391 40 181 00
5 4 90 391 40 181 00
6 23 10 391 40 181 00
6 23 50 391 40 181 00
7 19 90 391 40 181 00
7 19 80 391 30 282 00
8 1 70 391 30 282 00
8 1 70 391 30 282 00
9 15 60 391 40 282 00
9 15 50 391 40 282 00
10 4 40 391 40 282 00
10 4 40 391 40 282 00
Column 1 has values from 1 to 300, each repeated n times (in this example, n=2). Each unique value in column 1 is assigned a value from Column 2 (range from 1 to 25). Therefore, multiple values in Column 1 can get the same value in Column 2 (eg. 1 and 3 in column 1 have value 5 in Column 2).
Groups are made up of values in Column 2 (again, range 1 to 25).
Eg. Group 1 = [ 1 5 23 ]
So what I need is to first isolate all the trials from Group 1
1 5 80 391 30 181 00
1 5 70 391 30 181 00
2 1 70 391 30 181 00
2 1 60 391 40 181 00
3 5 50 391 40 181 00
3 5 40 391 40 181 00
6 23 10 391 40 181 00
6 23 50 391 40 181 00
8 1 70 391 30 282 00
8 1 70 391 30 282 00
And then the result reorganised (multiple values in Column 1 get rearranged into a row) for each column 3 to 7 - eg. below for Column 3
80 70
70 60
50 40
10 50
70 70
To check, when there are N repetitions of "1" in column 1, then the output derived from column 3 should be N wide? Likewise for the output derived from column 4? If so, then where should the column 3 output go relative to column 4?
80 70 391 391 30 30
80 60 391 391 30 40
and so on?
Hi,
when there are N repetitions of "1" in column 1, then the output derived from column 3 should be N wide?
Yes.
Results from column 3 are separate from results from column 4 and column 5 etc..
i.e. one output file (Column 3) is
80 70
70 60
....
Then the results from Column 4 are
391 391
391 391 ..
etc..
anyone?

Questa domanda è chiusa.

Richiesto:

il 4 Dic 2013

Chiuso:

il 20 Ago 2021

Community Treasure Hunt

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

Start Hunting!

Translated by