select corresponding values out of different columns of a matrix
8 views (last 30 days)
Show older comments
Hi, We have a matrix (480 x 23) and we need to extract data from it. For example: in column 5 there are the numbers of 1 to 6 and we need to extract the numbers 1. At the same we need the corresponding reaction times of these values which can be found in column 14. Thus far, we have
[n,m]=size(trialList);
for k=1:n;
r = trialList(k,5);
if r == 1
disp ('trailList14');
end
end
We are able to find the 80 rows where number 1 is mentioned. But instead showing the 80 corresponding reaction times, Matlab shows 80 times the word 'triallist14'.
How will we be able to select the corresponding reaction times with the corresponding values of column 5?
0 Comments
Accepted Answer
More Answers (1)
Dotje123
on 4 May 2018
3 Comments
Stephen23
on 4 May 2018
@Julia Verhaegh: The problem is having lots of numbered variables, and then trying to access them. You would be much better of keeping your data together as much as possible, using vectors/matrices/arrays. When beginners use lots of numbered/sequential variable names then they force themselves into either copy-and-pasting code (huge waste of your time) or writing slow, complex, buggy code (huge waste of your computer's time). Read this to know more:
Once you keep your data in just a few arrays then accessing it is trivial using indexing. Indexing is neat, very simple, and extremely efficient. It avoids all of the problems with numbered variables (which are just de-facto indices, so why not turn them into real indices?).
Razvan Carbunescu
on 4 May 2018
While there might be a few more aspects to your question it seems like you are trying to compute medians for groups of values.
See Also
Categories
Find more on Creating, Deleting, and Querying Graphics Objects 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!