From: Nathan on
On Apr 19, 3:45 pm, "Rachael " <raor...(a)gmail.com> wrote:
> Hi all,
>
> I am a beginning Matlab user so please respond simply!
>
> I am trying to select rows from a matrix based on an ID column that is basically a random individual number.  Then once I select those values I have another for loop that does simple math on those rows.  My problem is that the for loop command it requires sequential numbers that increment by 1 or a given value to work for each iteration and mine are random.  I would like to index the place in the matrix ie. first row, second row, third row (it only has one column), but don't know how to do this.  
>
> Thanks for any help!!

Your question is a little confusing. Could you please provide some
code that shows what you have done so far, as well as give us an
example of what input data and output data should look like?

For loops don't require sequential numbers that increment by a certain
value.

A for loop can work on any vector as follows:

x = [1 6 8 4 5 9 7 2 3];
for n=x
disp(n)
end

To select a row from a matrix, you use the colon operator.

A = [1 2 3;4 5 6; 7 8 9];
B = A(2,:); %retrieve second row
disp(B)

Providing code and examples of what you want done is usually a lot
more helpful than a question in the form of a descriptive paragraph.

-Nathan
From: Rachael on
Nathan <ngreco32(a)gmail.com> wrote in message <98837510-e3d9-4237-9998-30b1f8dec322(a)v27g2000pro.googlegroups.com>...
> On Apr 19, 3:45 pm, "Rachael " <raor...(a)gmail.com> wrote:
> > Hi all,
> >
> > I am a beginning Matlab user so please respond simply!
> >
> > I am trying to select rows from a matrix based on an ID column that is basically a random individual number.  Then once I select those values I have another for loop that does simple math on those rows.  My problem is that the for loop command it requires sequential numbers that increment by 1 or a given value to work for each iteration and mine are random.  I would like to index the place in the matrix ie. first row, second row, third row (it only has one column), but don't know how to do this.  
> >
> > Thanks for any help!!
>
> Your question is a little confusing. Could you please provide some
> code that shows what you have done so far, as well as give us an
> example of what input data and output data should look like?
>
> For loops don't require sequential numbers that increment by a certain
> value.
>
> A for loop can work on any vector as follows:
>
> x = [1 6 8 4 5 9 7 2 3];
> for n=x
> disp(n)
> end
>
> To select a row from a matrix, you use the colon operator.
>
> A = [1 2 3;4 5 6; 7 8 9];
> B = A(2,:); %retrieve second row
> disp(B)
>
> Providing code and examples of what you want done is usually a lot
> more helpful than a question in the form of a descriptive paragraph.
>
> -Nathan

Hi,
Thanks for the reply. I didn't include code because it wasn't very close to working. But sample data is a good idea. I am using the 95414003 column as the ID column.

%Sample data (csv file)
%
%
% 18,7,2008,0,3,50,39647.0026600000,22,64,1,95414003,4,11,1,1,1,0,8445
% 18,7,2008,0,13,49,39647.0096100000,9,64,1,95414003,4,11,1,1,1,0,8445
% 18,7,2008,0,23,49,39647.0165500000,44,64,1,95414013,4,11,1,1,1,0,8445
% 18,7,2008,0,33,49,39647.0234900000,90,64,1,95414003,4,11,1,1,1,0,8445
% 18,7,2008,0,23,49,39647.0165500000,44,64,1,95414045,4,11,1,1,1,0,8445
% 18,7,2008,0,23,49,39647.0165500000,44,64,1,95414046,4,11,1,1,1,0,8445

I would like to select those the rows that have the individual IDs, summarize the data in those rows and then loop to the next ID.

Here is the code so far. I am having trouble selecting the rows with the individual IDs, but the embedded for loop is working.

hit=[];
BIRD=[];
for j=ID(1,1):ID(end,1);
BIRDy=actlig(:,11)==j;
BIRD=actlig(BIRDy,:);
for i=floor(BIRD(1,1)):floor(BIRD(end,1));
chunk=floor(BIRD(:,1))==i;
hit=[hit;sum(chunk)];
end
end


Thanks for your help.