Two Arrays Addressing a Matrix
Mostrar comentarios más antiguos
Okay, so I have a matrix:
R(p,t)=
1 2 3 . . . 716 717 718 719 720
1.234 1.532 1.024 . . . 1.536 1.004 1.035 0.245 0.985
And three arrays:
a= 1 2 3 4 5 6 7 8 9 10
b= 243 244 245 246 247 248 249 250 251 252 253
c= 621 622 623 624 625 626 627 628 629 630 631
I'd like to use the arrays to address sections of the matrix. Like: R(a,t)=
1 2 3 . . . 10
1.234 1.532 1.024 . . . 1.534
How do I...do that?
Respuestas (1)
Matt Fig
el 4 de Abr. de 2011
What does this mean: R(p,t)? Are you saying that R is a 2-by-N array? Why use p and t?
.
.
EDIT
O.k., so then do:
R(:,a) % Read as: all rows of R, and columns given by a.
.
.
EDIT-2
If you get an error, then you have left something out of the description.
R = round(rand(2,15)*200) % Use 15 instead of 720.
a = 1:10
R(:,a)
.
EDIT -3
The above was an example. I wasn't telling you to change your R. The example shows that if 'R' is 2-by-720, and 'a' is the integers 1 through 10, as you say, then there is no error.... If you don't like that example, try a different name.
R_EXAMPLE = round(rand(2,15)*200) % Use 15 instead of 720
a_EXAMPLE = 1:10
R_EXAMPLE(:,a_EXAMPLE)
As we can see by this example, there is no error when things are as you say they are. The conclusion is that things are not the way you say they are. Either R is smaller than you say, or a has a larger number in it than you show.
EDIT-4
So try this. Run the code in a script, and when you get the error, paste the exact text of the error and the output of a call to WHOS.
8 comentarios
Bosh
el 4 de Abr. de 2011
Bosh
el 4 de Abr. de 2011
Bosh
el 4 de Abr. de 2011
Matt Fig
el 4 de Abr. de 2011
I was showing you an EXAMPLE, not telling you to change R. You see, if R does indeed have 720 elements, and a is 1-10, then you shouldn't have gotten an error. Again, you left something out of the description, because you can see that the example works....
Bosh
el 4 de Abr. de 2011
Bosh
el 4 de Abr. de 2011
Bosh
el 4 de Abr. de 2011
Matt Fig
el 5 de Abr. de 2011
Of course it isn't necessary for R_EXAMPLE to be 2-by-720, ANY matrix which is 2-by-N where N>10 will work as an example to be indexed by 'a'. Notice that 720>10. If you are still complaining about the example, try this:
R_EXAMPLE = round(rand(2,720)*200) %720, though it doesn't matter!
a_EXAMPLE = 1:10
R_EXAMPLE(:,a_EXAMPLE)
As long as the number of elements in 'R' is greater than the maximum value in 'a', you will not get an error - whether it is 15 elements or 720 is irrelevant!
Categorías
Más información sobre Creating and Concatenating Matrices 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!