Thread Subject: labeling issue dumb programming

Subject: labeling issue dumb programming

From: Jimmy

Date: 4 Nov, 2009 11:19:02

Message: 1 of 3

I have a problem with discrete functions and labeling

In my program I collect a vector of different lengths say, x=[1 1 2 3 1.4142 2.2361 2.2361 8]

Length 1 and 2.2361 occurs 2 times and I would like to use this in the following manner...

I have a associated vector v, which stores all possible lengths (in 3D)
v=[1.0000 1.4142 1.7321 2.0000 2.2361 2.4495 2.8284...]

and I write the occurences of X as
X=[2 1 0 1 2 0...] which has the same length as v.
I read out X as (together with v) 1.0000 occurs 2 times, 1.4142 occurs 1 time, 1.7321 occurs 0 times and so forth...

But the problem is that to be able to create X I must loop over all possible lengths in v and check how many times they occur in x. This just does not seem right as it will be a very slow process. This seem to be a standard question, and I wonder if there there are functions to handle these types of questions/labeling issues? Any ideas would be highly appreciable.

Best regards!
  Jimmy

Subject: labeling issue dumb programming

From: Pekka Kumpulainen

Date: 4 Nov, 2009 11:55:04

Message: 2 of 3

"Jimmy " <matias@chalmers.se> wrote in message <hcrnv6$iik$1@fred.mathworks.com>...
> I have a problem with discrete functions and labeling
>
> In my program I collect a vector of different lengths say, x=[1 1 2 3 1.4142 2.2361 2.2361 8]
>
> Length 1 and 2.2361 occurs 2 times and I would like to use this in the following manner...
>
> I have a associated vector v, which stores all possible lengths (in 3D)
> v=[1.0000 1.4142 1.7321 2.0000 2.2361 2.4495 2.8284...]
>
> and I write the occurences of X as
> X=[2 1 0 1 2 0...] which has the same length as v.
> I read out X as (together with v) 1.0000 occurs 2 times, 1.4142 occurs 1 time, 1.7321 occurs 0 times and so forth...
>
> But the problem is that to be able to create X I must loop over all possible lengths in v and check how many times they occur in x. This just does not seem right as it will be a very slow process. This seem to be a standard question, and I wonder if there there are functions to handle these types of questions/labeling issues? Any ideas would be highly appreciable.
>
> Best regards!
> Jimmy

I posted a function howmany to FEX today. It counts the occurrences of values in an array. It doesn't count the ones not included (zero counts), you'll have to add those, intersect for example might help there.

Subject: labeling issue dumb programming

From: Bruno Luong

Date: 4 Nov, 2009 12:44:03

Message: 3 of 3

% Data
x=[1 1 2 3 1.4142 2.2361 2.2361 8];
v=[1.0000 1.4142 1.7321 2.0000 2.2361 2.4495 2.8284 1]

% Engine
[vu i j]=unique(v);
c=histc(x,vu);
count=c(j)

Bruno

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
length Jimmy 4 Nov, 2009 06:24:05
labeling Jimmy 4 Nov, 2009 06:24:03
rssFeed for this Thread

Contact us at files@mathworks.com