COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### consecutive array elements

• Email
• Follow

Hi everyone,
If I have a matrix of the form
x=[44 378 45 46 47 379 48 390 391 392 52 53 54 400 401];
I want to reduce the matrixsch that no set of adjacent elements are consecutive in which case only the first number is considered i.e, the resulting output is
y=[44 378 45 379 48 390 52 400];
Pls help. Thanx in advance.
 0
Reply astro 3/29/2010 2:33:08 PM

See related articles to this posting

"astro mmi" <pyarsa_madhu@yahoo.co.in> wrote in message <hoqdn4\$4bq\$1@fred.mathworks.com>...
> Hi everyone,
>    If I have a matrix of the form
> x=[44 378 45 46 47 379 48 390 391 392 52 53 54 400 401];
> I want to reduce the matrixsch that no set of adjacent elements are consecutive in which case only the first number is considered i.e, the resulting output is
> y=[44 378 45 379 48 390 52 400];
> Pls help. Thanx in advance.

one of the many solutions

v=[44 378 45 46 47 379 48 390 391 392 52 53 54 400 401];
r=v([true,diff(v)~=1])
%    r = 44   378    45   379    48   390    52   400

us
 0
Reply us 3/29/2010 2:55:21 PM

1 Replies
450 Views

Similar Articles

12/20/2013 4:54:33 PM
page loaded in 200393 ms. (0)

 Reply:

Similar Artilces:

deleting elements of one array by comparing it to the elements of another array
I m a newbie to LabVIEW and I have a very basic question. &nbsp; I have two arrays. The first array contains a certain set of elements &nbsp; For e.g.&nbsp; 1 2 3 4 5 6 &nbsp; The second array has another set of elements &nbsp; For eg. 2 5 6 &nbsp; Now I want to delete the elements 2 5 6 from the first array and plot the first array with the deleted elements on a waveform graph. &nbsp; Can anybody help me out? &nbsp; Thanks and regards. Hello,you could do something like this:<img src="http://forums.ni.com/attachments/ni/170/231758/1/Example_BD.png"...

Updating elements in Primary Array with elements from secondary array in different location/index
I have two arrays, a primary and secondary array. Each array is composed of cluster elements (name string, numeric value).&nbsp; The primary array is in the correct order that must not change.&nbsp; The secondary array contains the updated numeric values for corresponding name string.&nbsp; However, the elements in the secondary array are not in the same order as the primary. How would I do a swap so that the Primary array now contains the updated values and remains in the same order. I have created an example VI (LV 8.2) (which I thought would work) that only puts in the first ele...

Subtraction of arrays
How to make a subtraction of two arrays so that new array consist of subtracted elements on each by each basis, like this: a=[1 10 20] b=[3 10 30] c=a-b=[-2 -9 -29; 7 0 -20; 17 10 -10] Thanks! "Milos Milenkovic" <m.milenkovic@mathworks.com> wrote in message <h0t343\$hf0\$1@fred.mathworks.com>... > How to make a subtraction of two arrays so that new array consist of subtracted elements on each by each basis, like this: > a=[1 10 20] > b=[3 10 30] > c=a-b=[-2 -9 -29; 7 0 -20; 17 10 -10] > Thanks! A perfect job for bsxfun! a = [1 10 30] b = [3 10 30] c = bs...

1.08 (**) Eliminate consecutive duplicates of list elements. If a list contains repeated elements they should be replaced with a single copy of the element. The order of the elements should
I have long-loved Prolog. A prolog program is closely analogous to many special purpose languages and systems: * mindmaps * make/build systems * dataflow diagrams It is the last analogy that I wish to apply to a novice Prolog program. I've never mastered Prolog, but I'm hoping to make it through all 99 prolog problems and then move on to advanced topics like DCGs, and object-oriented Prolog, etc. But anyway, the first problem that I found difficult was problem number 8. It tooks me two days and a bit of help from "RLa" in irc://irc.freenode.net/##prolog to get it working: ...

Sorting a Hash of Arrays by an Element in the Array
Hello all- I have seen many old questions where people ask if this can be done, and many responses where people claim it is not possible. However, I believe I have done it successfully and that it is quite easy: for my \$key (sort {\$hash{\$a}->[0] <=> \$hash{\$b}->[0]} keys %hash) { print "\$key\n"; } Am I missing something??? It looks as if it can be done to me. Thanks, Alf Alf McLaughlin wrote: > for my \$key (sort {\$hash{\$a}->[0] <=> \$hash{\$b}->[0]} keys %hash) { > print "\$key\n"; > } > Am I missing something??? It looks as ...

comparing each element in an array with all others elements
Hallo, I am looking for the possiblility/formula for comparing each element in an array with all others elements in array. For example : a = [1 2 3 4; 6 2 1 0]; 1 should be compared (>) to whole a, 2 > a I thought on A = arrayfun(fun, S), but I was awaiting 64 output arrays for 8*8 comparisons. Did I missunderstood something? Thanks joe I don't see why you need all 64 permutations. For one thing, these will include the comparison of each element with itself, and each converse. Why not use just the combinations without replacement, like this: a = magic(2); c = nchoosek(1:nu...

How to delete array element and add to previous element
Hello, I have an array that has elements that are arrays. It looks like this(I'll call it array), it has: [ [POS1, POS2a\, POS2b, POS3, POS4], # this array is in position array[0] [POS2c\, POS2d\, POS2e], # this array is in position array[1] [POS2f\, POS2g\, POS2h], # this array is in position array[2] [POS1, POS2a\, POS2b, POS3, POS4] # this array is in position array[3] ] Notice that Im trying to escape the commas with the backslash in the array. Is this the proper ways to escape commas in arrays? The POS2's are separated...

find if an array has any element present in another array
Hi, I have 2 lists a=[1,2,3,4] b=[2,4,6,7,8] I want to find if there are any elements present in "a" which are also present in "b". I jus wanna "true" or "false" answer if both of the arrays have any element in common. Is there any inbuilt functions like "include?" for this purpose?? Thanks in Advance. -- Posted via http://www.ruby-forum.com/. Le Thu, 30 Apr 2009 05:52:26 -0500, Charanya Nagarajan <charanya.nagarajan@tcs.com> a écrit : > I have 2 lists > > a=[1,2,3,4] > b=[2,4,6,7,8] > > I want to find if...

Accessing elements in array ref of array references
Currently I'm comparing the first value of each of the array references (which are stored in an array reference \$ref_ref) as follows: if(map(\$_->[0] =~ /\$keyword/i,@\$ref_ref)) { # Do something cunningly clever... } What I was wondering about (for no particular reason) is doing something like: if(map(/\$keyword/i,cool_function(@\$ref_ref, 0))) { # Do something equally cunningly clever... } Any idea's? (or should I get back to work ;) fatted wrote: > Currently I'm comparing the first value of each of the array > references (which are stored in an array reference \$ref_re...

time to read array vs. element of array
Hi there, I have difficulties in understanding why the first example shown below takes almost twice as long as the second one. % first example tic; iterations = 1000000; for i=1:iterations r = rand(1,1); if r<0.5 end end toc; Elapsed time is 2.871286 seconds. % second example tic; iterations = 1000000; for i=1:iterations r = rand(1,1); if r(1)<0.5 end end toc; Elapsed time is 1.410524 seconds. Interestingly, if I replace r = rand(1,1) by a fixed number, say r=5, then the second example becomes much ...