Thread Subject: Interpolating with multiple subjects

Subject: Interpolating with multiple subjects

From: Ryan Utz

Date: 7 Sep, 2009 22:14:02

Message: 1 of 4

Hi all,

I have a dataset with multiple sites and I need to interpolate a single value for each site. The data look like this, where the first column is the site, the second is a size class, and the third is a cumulative proportion:

A=
1 0.125 1
1 0.25 0.67993
1 0.5 0.45137
1 1 0.36642
1 2 0.28274
1 4 0.16574
1 8 0.043755
2 0.125 1
2 0.25 0.81988
2 0.5 0.56711
2 1 0.40474
2 2 0.28568
2 4 0.13994
2 8 0.035264

I need to figure out what size class corresponds to the 0.5 cumulative proportion. With only one site, this is very easily done with the following command:

>> interp1(A(:,3),A(:,2),.5)

But I have to do this for each site (out of 100). Anyone know a way to automate this command? I could do it in SAS using a BY command, but I'm not terrific with Matlab and am getting nowhere on my own...

Thanks ahead of time,
Ryan

Subject: Interpolating with multiple subjects

From: dpb

Date: 7 Sep, 2009 22:29:08

Message: 2 of 4

Ryan Utz wrote:
...[data elided for brevity]...

> I need to figure out what size class corresponds to the 0.5
> cumulative proportion. With only one site, this is very easily done
> with the following command:
>
>>> interp1(A(:,3),A(:,2),.5)
>
> But I have to do this for each site (out of 100). Anyone know a way
> to automate this command? ...

For your sample data one straightahead solution...

 > u=unique(x(:,1));
for i=1:length(u)
   j=u(i);
   idx=find(x(:,1)==j);
   interp1(x(idx,3),x(idx,2),0.5)
end
ans =
     0.4468
ans =
     0.7067
 >>

--

Subject: Interpolating with multiple subjects

From: dpb

Date: 8 Sep, 2009 02:57:35

Message: 3 of 4

dpb wrote:
> Ryan Utz wrote:
> ...[data elided for brevity]...
>
>> I need to figure out what size class corresponds to the 0.5
>> cumulative proportion. With only one site, this is very easily done
>> with the following command:
>>
>>>> interp1(A(:,3),A(:,2),.5)
>>
>> But I have to do this for each site (out of 100). Anyone know a way
>> to automate this command? ...
>
> For your sample data one straightahead solution...
>
> > u=unique(x(:,1));
> for i=1:length(u)
> j=u(i);
> idx=find(x(:,1)==j);
> interp1(x(idx,3),x(idx,2),0.5)
> end
> ans =
> 0.4468
> ans =
> 0.7067
> >>

Also note that as long as your data sets have a fixed number of members
you could simply compute start/stop indices for each group based on the
total number/group but the above handles the more general case.

--

Subject: Interpolating with multiple subjects

From: Ryan Utz

Date: 8 Sep, 2009 14:35:20

Message: 4 of 4

Once again, the Matlab Newsreader helps makes the program usable and useful. Thanks everyone!

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
interpolation Sprinceana 8 Sep, 2009 11:16:07
bygroups Ryan Utz 7 Sep, 2009 18:14:06
interp1 Ryan Utz 7 Sep, 2009 18:14:06
rssFeed for this Thread

Contact us at files@mathworks.com