How do I create a set of variables from specific coordinate values in a square matrix?
Mostrar comentarios más antiguos
I have a 30x30 matrix of numeric values. The horizontal and vertical coordinates are each the same 30 locations, with the values in the matrix being the distance between one location to another (x,y). I've calculated a 30x1 vector with a specific 'path' through the matrix locations. I am trying to create a set of 30 variables with the matrix values for 30 matrix coordinates, where each variable is the value of the coordinate in the matrix corresponding to (the first 'path' value, the next path value).
So given the distance matrix (dm) 30x30
and a 'path' vector 30x1 with a given order of the numbers 1 through 30
how to create 30 variables, each with the dm values of one path number to the next
example
6x6 matrix given path=[2;4;6;1;3;5] var01=matrix value at (2,4) var02=matrix value at (4,6) var03=matrix value at (6,1) var04=matrix value at (1,3) var05=matrix value at (3,5) var06=matrix value at (5,2) <------ last y value=first path value
This is applied in biology for ranking multiple sequence alignments. I am new to Matlab, and I appreciate any help with this problem, it is beyond my current skill level. This is for a project in my bioinformatics class, I'm going for a computational biology degree.
thx
1 comentario
Adam Quintero
el 5 de Jun. de 2011
Respuesta aceptada
Más respuestas (1)
Paulo Silva
el 5 de Jun. de 2011
0 votos
4 comentarios
Matt Fig
el 5 de Jun. de 2011
As the FAQ says, you really should figure out a different way to do what you want to do. It is a bad idea to fill your workspace with many variables because then your next question will be, "I have all of the variables and I need to do X with them but I can't figure out how?" Then after you figure that out, your complaint will be, "I have an error and I can't figure out where because it occurs in and EVAL statement." or "Why is my code sooo slow?"
Adam Quintero
el 5 de Jun. de 2011
Matt Fig
el 5 de Jun. de 2011
Let me ask you, why not just have one variable named var which has all of your values? Then var(1) is equal to your var01, var(30) is equal to your var30. Why not do this? A vector var is much easier to deal with than 30 different variables!
Adam Quintero
el 5 de Jun. de 2011
Categorías
Más información sobre Genomics and Next Generation Sequencing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!