select corresponding values out of different columns of a matrix
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Più risposte (1)
Dotje123
il 4 Mag 2018
3 Commenti
Stephen23
il 4 Mag 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
il 4 Mag 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.
Vedere anche
Categorie
Scopri di più su Creating, Deleting, and Querying Graphics Objects in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!