Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
??? Index exceeds matrix dimensions

Subject: ??? Index exceeds matrix dimensions

From: Moon Datta

Date: 16 Aug, 2012 09:02:06

Message: 1 of 7

I have written a programme in matlab for extracting data having value less then 35 from the matrix E as below----
for a = 1:length(E(:,1));
while (E(a,1) < 35)
      Time(a, :) = [];
end
 end
but its giving the error like below---

??? Index exceeds matrix dimensions.

Error in ==> while (Elv(a,1) < 35)

how to solve this problem?

Subject: ??? Index exceeds matrix dimensions

From: NoLi

Date: 16 Aug, 2012 09:55:16

Message: 2 of 7

Hy,
much more easier will be
[indexRow,indexColumn]=find(E<35); %For 2-dimensional E

indexRow/Column will give you the oposition of elements of E < 35.

Regards

Your error message I cannot explain, only if you use different matrices
in the determination of length (line: for ...) and in the comparison
(line: while ...)


Am Donnerstag, 16. August 2012 11:02:06 UTC+2 schrieb Moon Datta:
> I have written a programme in matlab for extracting data having value less then 35 from the matrix E as below----
>
> for a = 1:length(E(:,1));
>
> while (E(a,1) < 35)
>
> Time(a, :) = [];
>
> end
>
> end
>
> but its giving the error like below---
>
>
>
> ??? Index exceeds matrix dimensions.
>
>
>
> Error in ==> while (Elv(a,1) < 35)
>
>
>
> how to solve this problem?

Subject: ??? Index exceeds matrix dimensions

From: Moon Datta

Date: 16 Aug, 2012 10:14:07

Message: 3 of 7

"Moon Datta" wrote in message <k0icue$nsk$1@newscl01ah.mathworks.com>...
> I have written a programme in matlab for extracting data having value less then 35 from the matrix E as below----
> for a = 1:length(E(:,1));
> while (E(a,1) < 35)
> Time(a, :) = [];
> end
> end
> but its giving the error like below---
>
> ??? Index exceeds matrix dimensions.
>
> Error in ==> while (Elv(a,1) < 35)
>
> how to solve this problem?


Thanks sir for your kind reply.
but I want to delete the rows which containing the values less than 35.

Subject: ??? Index exceeds matrix dimensions

From: Bruno Luong

Date: 16 Aug, 2012 11:28:07

Message: 4 of 7

"Moon Datta" wrote in message <k0icue$nsk$1@newscl01ah.mathworks.com>...
> I have written a programme in matlab for extracting data having value less then 35 from the matrix E as below----
> for a = 1:length(E(:,1));
> while (E(a,1) < 35)
> Time(a, :) = [];
> end
> end
> but its giving the error like below---
>
> ??? Index exceeds matrix dimensions.
>
> Error in ==> while (Elv(a,1) < 35)
>
> how to solve this problem?

You make two errors:
- Why you cascade for-loop with the why loop? One of those is enough.
- Furthermore when a row get deleted during the loop, the array E get smaller than the index 'a' should not go to the original length of E.

A much better alternative is not using loop at all but can be achieve the goal with MATLAB matrix indexing or logical indexing stock functions.

Bruno

Subject: ??? Index exceeds matrix dimensions

From: Christopher Creutzig

Date: 16 Aug, 2012 12:01:12

Message: 5 of 7

On 16.08.12 11:02, Moon Datta wrote:
> I have written a programme in matlab for extracting data having value less then 35 from the matrix E as below----
> for a = 1:length(E(:,1));
> while (E(a,1) < 35)
> Time(a, :) = [];
> end
> end

That is an infinite loop whenever you have any E(a,1)<35, since the
assignment to Time(a,:) does not change E.


> but its giving the error like below---
>
> ??? Index exceeds matrix dimensions.
>
> Error in ==> while (Elv(a,1) < 35)

The code you posted does not contain any Elv. I guess both E and Time
are in fact Elv in your code? If so,

1. Please don't do that. Always(!) post exactly the code you tested,
   using copy&paste – obviously you should test after having trimmed it
   down to the shortest and most readable version that shows the
   behavior you don't understand. Not just out of respect for your
   readers' time; that is and will probably remain one of the most
   useful techniques for debugging and understanding code anyway.

2. The outer loop runs up to the size E (or Elv, Time) had at the
   beginning of the loop. If that matrix gets smaller while running
   through the loop, the error message you quoted is to be expected.

Use what NoLi wrote instead:

[indexRow,indexColumn]=find(E<35); %For 2-dimensional E
E(indexRow,:)=[];



Christopher

Subject: ??? Index exceeds matrix dimensions

From: Christopher Creutzig

Date: 16 Aug, 2012 12:02:09

Message: 6 of 7

On 16.08.12 14:01, Christopher Creutzig wrote:

> Use what NoLi wrote instead:
>
> [indexRow,indexColumn]=find(E<35); %For 2-dimensional E

Sorry, that should have been

indexRow = find(E(:,1)<35);
E(indexRow,:) = [];


Christopher

Subject: ??? Index exceeds matrix dimensions

From: nl.doc@arcor.de

Date: 16 Aug, 2012 12:13:10

Message: 7 of 7

Try

E(any(E<35,2),:)=[];

E<35 produces a matrix containing 0 and 1 of the same size than E

any(E<35,2): looks for each row, if any (at least one) of the values in a row is 1, the value will be 1. So it returns a vector of the a length equally to the number of rows in E, filled by 0 and 1.

Those rows of E are eliminated, where this vector has a 1.

Example:
E =39.7395 67.3655 66.1094
   22.5165 22.3040 61.8814
   17.2452 23.6504 5.8518
   35.5520 2.7905 62.7871

>> E<35
ans =0 0 0
     1 1 0
     1 1 1
     0 1 0
>> any(E<35,2)
ans =0
     1
     1
     1
>> E(any(E<35),:)=[]
E =39.7395 67.3655 66.1094

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us