"Index exceeds matrix dimensions."
Show older comments
Hi, can somebody figure out why I get this error message? Thank you very much!
columnsA=length(A); % number of columns in my dataset A
disp(columnsA);
waves=i; %i is a number I found by iteration before but for next should be
%fixed
j=2; % iteration variable
k=1; % iteration variable
B=ones (1,(columnsA/2)); %new vector where I want to store the iterated
%values
while (j<= (columnsA/2) && k < ((columnsA/2)-1)) %iteratio over columns
%in dataset in specific row waves
x = A(waves,j); %x is values I want to store in new vector from
%dataset A at location waves, j
B(1,k)=x; % store the new value in B
j=j+2; % increse j by 2 (only want to store every other value from
%that row
k=k+1; % increase iterator for vector B
end
Accepted Answer
More Answers (1)
the cyclist
on 17 May 2016
This code runs to completion
A = rand(10,6);
columnsA=length(A); % number of columns in my dataset A
disp(columnsA);
waves=1; %i is a number I found by iteration before but for next should be
%fixed
j=2; % iteration variable
k=1; % iteration variable
B=ones (1,(columnsA/2)); %new vector where I want to store the iterated
%values
while (j<= (columnsA/2) && k < ((columnsA/2)-1)) %iteratio over columns
%in dataset in specific row waves
x = A(waves,j); %x is values I want to store in new vector from
%dataset A at location waves, j
B(1,k)=x; % store the new value in B
j=j+2; % increse j by 2 (only want to store every other value from
%that row
k=k+1; % increase iterator for vector B
end
The difference from what you posted is that I added some made-up data at the beginning, and I set the values of "waves" to 1, since I don't know what "i" is.
You'll need to specify the problem better, for example by posting your real data and value of i.
3 Comments
Guillaume
on 17 May 2016
If you'd made your matrix |A| taller (e.g. 16 rows) , you'd have hit the same problem due to the use of |length|.
the cyclist
on 17 May 2016
My code still runs to completion if I swap in
A = rand(16,10);
So, I'm still unclear on am514's problem.
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!