MATLAB Answers


how to not exceed limits of the matrix column

Asked by minion001 on 10 Sep 2017
Latest activity Edited by José-Luis
on 10 Sep 2017
for eg, i have matrix A=[4 6 3 8 9 5;1 7 2 4 3 4;7 8 5 6 1 2; 1 8 4 7 10 6;] and i use a for loop to go across the column, for i =1:col .... how do i stop it before getting error of matrix exceeds dimensions


Sign in to comment.

1 Answer

Answer by José-Luis
on 10 Sep 2017
 Accepted Answer

your_array = rand(10,16)
%looping through all columns
for ii=your_array
%ii now contains all values in column


Show 1 older comment
Why do you do i=i+1?
It is unnecessary, if what you want is to increment the iterator index.
Why do you call both loop iterators i?
Call the first one ii and the second one jj or whatever, but definitely not the same name.
i did that but how do i stop getting error when im at column 6 and its searching for elements next to it, where there isn't any elements present, resulting in matrix exceeds dimensions
Columns 1-5 of what? You are not indexing into A and that is the array whose columns you are looping on.
Please use the debugger. Place a breakpoint in the line that's giving you grief and look at the arrays you are indexing into.

Sign in to comment.