Two Arrays Addressing a Matrix

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
Matt Fig el 4 de Abr. de 2011

0 votos

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
Bosh el 4 de Abr. de 2011
R(p,t)=is a 2-by-720 array, and yeah, I just used p and t because that's what it actually is in the file.
i.e.:
load('Known_1.mat')
figure
q=ECG_1;
r=(1:1:length(q(:,1))')';
[sp,values]=spaps(r,q,10);
t=values';
p=(1:1:length(t))';
R=[p,t];
Bosh
Bosh el 4 de Abr. de 2011
'doesn't work man.
??? Index exceeds matrix dimensions.
Bosh
Bosh el 4 de Abr. de 2011
No man; R needs to stay 2x720
Matt Fig
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
Bosh el 4 de Abr. de 2011
Okay: here's where a is defined and some of the output. I'm sorry man; I'm just really stuck.
load('Known_1.mat')
figure
q=ECG_1;
r=(1:1:length(q(:,1))')';
[sp,values]=spaps(r,q,10);
t=values';
p=(1:1:length(t))';
R=[p,t]'
plot(p,t);
v=.65*max(t);
z=find(t(:,1)>v);
Z=t(z);
u=extrema(Z)
i=[find(ismember(t,u))]
I=i-9
U=bsxfun(@plus, I, 0:i(1)-I(1))
if length(U(:,1))==3;
a=(U(1,:)')
b=(U(2,:)');
c=(U(3,:)');
----------------------
u =
1.4674
1.2646
1.2037
i =
100
432
660
I =
91
423
651
U =
91 92 93 94 95 96 97 98 99 100
423 424 425 426 427 428 429 430 431 432
651 652 653 654 655 656 657 658 659 660
a =
91
92
93
94
95
96
97
98
99
100
Bosh
Bosh el 4 de Abr. de 2011
Also, R is seriously two columns, one which is 1-720 by intervals of 1 and the other is values between -0.5 and 1.5.
Bosh
Bosh el 4 de Abr. de 2011
That R_EXAMPLE, by the by, isn't anywhere close to the dimensions I specified.
Matt Fig
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!

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Preguntada:

el 4 de Abr. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by