Index exceeds matrix dimensions Error

Hello
I am trying to access data from a document and the data gets imported correctly. The array for data is a 20 x 20 size array, but when I try to access row 2, it gives the index exceeds matrix dimensions error.
Here is my code:
figure(1);
markers=['+' 'o' '*' '.' 'x' 's' 'd' '^' 'v' '<' '>' 'p' 'h'];
location = 1;
disp(size(data()));
for i=1:num_trials
for j=1:num_sensors
col = 5 + (j-.5) * 2;
plot(location * ones(size(data(:,col,i))),data(:,col,i),'.'); hold on;
end
location = location+1;
end
grid on;
The specific line generating the error is: plot(location * ones(size(data(:,col,i))),data(:,col,i),'.'); hold on;

 Accepted Answer

If "data" is 20x20, why are you indexing into it as a 3D array? E.g.,
data(:,col,i)
What are the values of num_trials and num_sensors? That could be another source of problems.

7 Comments

num_trials is 10 and num_sensors is 8
I had the colon there because i needed to get everything out of that location for the data collection. What would be a better way to do this?
What is "data"? A double array, cell array, or what?
double with 1x1 struct cells of unknown struct type
This is not clear to me. Is it a struct with fields that are cell arrays that contain double arrays? Or what? E.g., what does class(data) return?
Data is taking in sensor data from a sensor strip. For example, when i run disp(data) i get:
Columns 1 through 10
10 2 1 119 28 4559 101 4570 58 4457
10 2 2 119 28 4545 100 4581 58 4450
10 2 3 119 29 4562 101 4572 58 4444
10 2 4 119 29 4552 102 4570 58 4444
10 2 5 119 28 4553 101 4566 58 4442
10 2 6 119 27 4557 100 4577 56 4456
10 2 7 119 26 4557 99 4570 56 4446
10 2 8 119 27 4555 100 4573 56 4455
10 2 9 119 27 4550 100 4575 56 4450
10 2 10 119 26 4560 99 4569 55 4449
10 2 1 119 28 4559 101 4569 58 4455
10 2 2 119 28 4564 101 4576 57 4452
10 2 3 119 28 4557 100 4577 57 4445
10 2 4 119 28 4557 100 4587 57 4449
10 2 5 119 27 4554 99 4573 57 4447
10 2 6 119 28 4559 99 4577 57 4451
10 2 7 119 27 4558 99 4565 56 4455
10 2 8 119 27 4552 99 4567 57 4441
10 2 9 119 27 4552 100 4577 57 4453
10 2 10 119 27 4556 100 4579 57 4449
Columns 11 through 20
147 4614 288 5109 98 4417 195 4478 188 4390
147 4612 287 5106 98 4419 195 4486 188 4398
147 4613 287 5107 98 4408 195 4481 189 4389
148 4611 287 5111 98 4413 195 4486 188 4395
147 4614 287 5102 98 4410 194 4485 187 4390
146 4606 285 5106 97 4415 193 4479 187 4398
145 4607 285 5107 97 4417 194 4481 188 4395
145 4617 285 5111 97 4420 194 4479 188 4392
145 4612 285 5109 97 4412 193 4479 188 4392
145 4614 284 5107 96 4413 194 4476 189 4391
147 4609 286 5108 98 4421 195 4471 191 4392
147 4613 286 5105 97 4414 195 4478 191 4389
146 4613 286 5110 97 4412 194 4479 190 4392
147 4613 286 5105 97 4407 195 4480 190 4400
147 4609 286 5105 97 4415 195 4479 189 4393
146 4614 286 5102 97 4420 195 4473 191 4391
146 4600 286 5106 97 4418 195 4473 190 4391
146 4618 286 5110 98 4418 195 4474 191 4404
147 4611 286 5106 97 4415 195 4490 190 4397
146 4608 286 5102 97 4416 195 4473 191 4399
If class(data) returns 'double', what does the phrase "struct with fields that are cell arrays that contain double arrays" mean specifically?
Actually, I think it works now. Thanks!

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!