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:
How to automatically loop over the combinations

Subject: How to automatically loop over the combinations

From: Roy

Date: 18 Apr, 2013 12:11:09

Message: 1 of 28

first of all I appreciate whoever sees this post and try giving a solution.Thanks in advance

My questions is as follows,

A part of main Program

 AID=30;
 SID=50;
[rss_dBm1,rss_dBm2,rss_dBm3,rss_dBm4,y1,y2,y3,y4]=sample(Blink,AID,SID)

Note: The AID has different ID's as 30,50,52,54,55,57 (same as SID) The SID has different ID's as 30,50,52,54,55,57 ( same as AID)
Here the AID and SID is manually entered from the user to check the below anchorchannel and source channel condition(stated in the function) and check if such combination exist it will display the rss values if not it will return NaN.

calling function

  function [rss_dBm1,rss_dBm2,rss_dBm3,rss_dBm4,y1,y2,y3,y4]=sample(Blink,AID,SID)


 for i=1:length(Blink) %Blink=<500x1 cell> inside which several blinks are present
 S=cell2mat(Blink(i)); % with information on AID,SID,agc
   for j=1:length(S)
    if S(j).AID==AID && S(j).SID==SID
       if S(j).AnchorChannel==0 && S(j).SourceChannel==0 %Anchor-source channel
        y=S(j).agc; %agc is present in every blink to calculate rss %combination
        rss_dB1(i)= -(33+y*(89-33)/(29-1));
        else
            rss_dB1(i)=0;
            isempty(rss_dB1(i))
        end
        if S(j).AnchorChannel==0 && S(j).SourceChannel==1
        y=S(j).agc;
        rss_dB2(i)= -(33+y*(89-33)/(29-1));
        else
            rss_dB2(i)=0;
            isempty(rss_dB2(i))
        end
        if S(j).AnchorChannel==1 && S(j).SourceChannel==0
        y=S(j).agc;
        rss_dB3(i)= -(33+y*(89-33)/(29-1));
        else
            rss_dB3(i)=0;
            isempty(rss_dB3(i))
        end
        if S(j).AnchorChan==1 && S(j).SourceChan==1
        y=S(j).agc;
        rss_dB4(i)= -(33+y*(89-33)/(29-1));
        else
            rss_dB4(i)=0;
            isempty(rss_dB4(i))
        end
    end
  end
end


   rss_dB1(rss_dB1==0)=[];
   rss_dB2(rss_dB2==0)=[];
   rss_dB3(rss_dB3==0)=[];
   rss_dB4(rss_dB4==0)=[];
   y1=std(rss_dB1);
   y2=std(rss_dB2);
   y3=std(rss_dB3);
   y4=std(rss_dB4);
   rss_dBm1=sum(rss_dB1(:))/length(rss_dB1);
   rss_dBm2=sum(rss_dB2(:))/length(rss_dB2);
   rss_dBm3=sum(rss_dB3(:))/length(rss_dB3);
   rss_dBm4=sum(rss_dB4(:))/length(rss_dB4);

    disp([sprintf('The rss value with A-Chan 0 and S-Chan 0 is %0.0f',rss_dBm1)]);
    disp([sprintf('The rss value with A-Chan 0 and S-Chan 1 is %0.0f',rss_dBm2)]);
    disp([sprintf('The rss value with A-Chan 1 and S-Chan 0 is %0.0f',rss_dBm3)]);
    disp([sprintf('The rss value with A-Chan 1 and S-Chan 1 is %0.0f',rss_dBm4)]);

Now my question is how to automatically check the different combinations of AID and SID without giving the user input ?. if this make sense it should loop over every combinations of AID and SID and return the "rss" result for all possible combinations of AID SID with anchor channel and source channel

Result for one combination: AID=30 SID=50

The rss value with A-Chan 0 and S-Chan 0 is -68
The rss value with A-Chan 0 and S-Chan 1 is -73
The rss value with A-Chan 1 and S-Chan 0 is -73
The rss value with A-Chan 1 and S-Chan 1 is -76

rss_dBm1 =-68
rss_dBm2 =-72.8621
rss_dBm3 =-73
rss_dBm4 = -76


y1 = 1.4142
y2 = 1.4072
y3 = 0
y4 = 1.1547

The above is a result for one AID(30) SID(50) combination.But I want to loop over all the possible AID(30 50 .... 57) SID(30 50 ... 57) combinations automatically and return their individual results.

Subject: How to automatically loop over the combinations

From: dpb

Date: 18 Apr, 2013 14:16:35

Message: 2 of 28

On 4/18/2013 7:11 AM, Roy wrote:
...

> Note: The AID has different ID's as 30,50,52,54,55,57 (same as SID) The
> SID has different ID's as 30,50,52,54,55,57 ( same as AID)
...

>
> Now my question is how to automatically check the different combinations
> of AID and SID without giving the user input? If this make sense it
> should loop over every combinations of AID and SID and return the "rss"
> result for all possible combinations of AID SID with anchor channel and
> source channel
...

> The above is a result for one AID(30) SID(50) combination.But I want to
> loop over all the possible AID(30 50 .... 57) SID(30 50 ... 57)
> combinations automatically and return their individual results.

Use unique() over the two variables and then loop over those two lists
to find the intersections of the various pairs.

--

Subject: How to automatically loop over the combinations

From: Roy

Date: 18 Apr, 2013 14:35:10

Message: 3 of 28


>
> Use unique() over the two variables and then loop over those two lists
> to find the intersections of the various pairs.
>
>

Thank you !

But can you show it in the program I have pasted ? I tried this now but I could not find a proper output ! Your help is highly appreciated.

Regards
Roy

Subject: How to automatically loop over the combinations

From: dpb

Date: 18 Apr, 2013 17:29:43

Message: 4 of 28

On 4/18/2013 9:35 AM, Roy wrote:
>
>>
>> Use unique() over the two variables and then loop over those two lists
>> to find the intersections of the various pairs.
>>
>>
>
> Thank you !
>
> But can you show it in the program I have pasted ? I tried this now but
> I could not find a proper output ! Your help is highly appreciated.

Well, on reading the function looks like it could be simplified quite a
bit...

Questions -- are the two SID AID arrays same length and non-duplicated
values in each I now presume that didn't presume necessarily so in
giving previous advice?

Is order significant?

Are the channel flags either 0|1 only or are there possible other or
missing values?

Do you have a problem if the results are returned as combined cell array
rather than separate variables?

--

Subject: How to automatically loop over the combinations

From: dpb

Date: 18 Apr, 2013 22:07:04

Message: 5 of 28

On 4/18/2013 7:11 AM, Roy wrote:
...

> AID=30;
> SID=50;
> [rss_dBm1,rss_dBm2,rss_dBm3,rss_dBm4,y1,y2,y3,y4]=sample(Blink,AID,SID)
>
> Note: The AID has different ID's as 30,50,52,54,55,57 (same as SID) The
> SID has different ID's as 30,50,52,54,55,57 ( same as AID)
> Here the AID and SID is manually entered from the user to check the
> below anchorchannel and source channel condition(stated in the function)
> and check if such combination exist it will display the rss values if
> not it will return NaN.
>
> calling function

function [rss,y]=sample(Blink,AID,SID)
   idCh = [0 0; 0 1; 1 0; 1 1]; % a convenient array for chnls
   for i=1:length(Blink) %Blink=<500x1 cell>
     S=cell2mat(Blink(i));
     rss=nan(length(S),4); % initialize the array to NaN
     y=nan(1,4);
     idxID = S.AID==AID & S.SID==SID; % logical array of wanted
     for j=1:4
       ixCh=ismember([S.AnchorChannel S.SourceChannel],idCh(j),'rows');
       rss(:,j)= -(33+S.agc*(89-33)/(29-1));
     end
     y=nanstd(rss);
     rss_dBm=nanmean(rss);
   end

...

See if the above doesn't do what yours did (for a single combination of
IDs still) where the rss array is the same as your four values each in
the corresponding column. Likewise for y and rss_dBm.

--

Subject: How to automatically loop over the combinations

From: dpb

Date: 18 Apr, 2013 23:00:52

Message: 6 of 28

On 4/18/2013 5:07 PM, dpb wrote:
...

> function [rss,y]=sample(Blink,AID,SID)
> idCh = [0 0; 0 1; 1 0; 1 1]; % a convenient array for chnls
...

> ixCh=ismember([S.AnchorChannel S.SourceChannel],idCh(j),'rows');
> rss(:,j)= -(33+S.agc*(89-33)/(29-1));
> end
...

Oops, left out the indexing vector after going to all the trouble to
generate it...

rss(:,j)= -(33+S(ixCh).agc*(89-33)/(29-1));

--

Subject: How to automatically loop over the combinations

From: Roy

Date: 19 Apr, 2013 07:25:10

Message: 7 of 28

> Well, on reading the function looks like it could be simplified quite a
> bit...
>
> Questions -- are the two SID AID arrays same length and non-duplicated
> values in each I now presume that didn't presume necessarily so in
> giving previous advice?
>
> Is order significant?
>
> Are the channel flags either 0|1 only or are there possible other or
> missing values?
>
> Do you have a problem if the results are returned as combined cell array
> rather than separate variables?
>
Hello dpb,
yes the length of both the arrays are same. No changes in that.

There are just four combinations just like I have mentioned it in the function.

Well I would like to see the same I have pasted my result or is there any better ways to do ?

Subject: How to automatically loop over the combinations

From: Roy

Date: 19 Apr, 2013 07:34:09

Message: 8 of 28

dpb <none@non.net> wrote in message <kkpqqg$599$1@speranza.aioe.org>...
> On 4/18/2013 7:11 AM, Roy wrote:
> ...
>
> > AID=30;
> > SID=50;
> > [rss_dBm1,rss_dBm2,rss_dBm3,rss_dBm4,y1,y2,y3,y4]=sample(Blink,AID,SID)
> >
> > Note: The AID has different ID's as 30,50,52,54,55,57 (same as SID) The
> > SID has different ID's as 30,50,52,54,55,57 ( same as AID)
> > Here the AID and SID is manually entered from the user to check the
> > below anchorchannel and source channel condition(stated in the function)
> > and check if such combination exist it will display the rss values if
> > not it will return NaN.
> >
> > calling function
>
> function [rss,y]=sample(Blink,AID,SID)
> idCh = [0 0; 0 1; 1 0; 1 1]; % a convenient array for chnls
> for i=1:length(Blink) %Blink=<500x1 cell>
> S=cell2mat(Blink(i));
> rss=nan(length(S),4); % initialize the array to NaN
> y=nan(1,4);
> idxID = S.AID==AID & S.SID==SID; % logical array of wanted
> for j=1:4
> ixCh=ismember([S.AnchorChannel S.SourceChannel],idCh(j),'rows');
> rss(:,j)= -(33+S.agc*(89-33)/(29-1));
> end
> y=nanstd(rss);
> rss_dBm=nanmean(rss);
> end
>
> ...
>
> See if the above doesn't do what yours did (for a single combination of
> IDs still) where the rss array is the same as your four values each in
> the corresponding column. Likewise for y and rss_dBm.
>
> --



When I applied this above step you mentioned it showed me too much input arguments.

Subject: How to automatically loop over the combinations

From: Roy

Date: 19 Apr, 2013 07:39:08

Message: 9 of 28

dpb <none@non.net> wrote in message <kkptvb$cf2$1@speranza.aioe.org>...
> On 4/18/2013 5:07 PM, dpb wrote:
> ...
>
> > function [rss,y]=sample(Blink,AID,SID)
> > idCh = [0 0; 0 1; 1 0; 1 1]; % a convenient array for chnls
> ...
>
> > ixCh=ismember([S.AnchorChannel S.SourceChannel],idCh(j),'rows');
> > rss(:,j)= -(33+S.agc*(89-33)/(29-1));
> > end
> ...
>
> Oops, left out the indexing vector after going to all the trouble to
> generate it...
>
> rss(:,j)= -(33+S(ixCh).agc*(89-33)/(29-1));
>
> --



it pops an error like this

??? Error using ==> ismember at 184
A and S must have the same number of columns.

Error in ==> samplefunction at 9
       ixCh=ismember([S(j).AnchorChannel S(j).SourceChannel],idCh(j),'rows');


Actually I use S(j) becaz it can collect the values from J.

Subject: How to automatically loop over the combinations

From: dpb

Date: 19 Apr, 2013 13:23:41

Message: 10 of 28

On 4/19/2013 2:39 AM, Roy wrote:
> dpb <none@non.net> wrote in message <kkptvb$cf2$1@speranza.aioe.org>...
>> On 4/18/2013 5:07 PM, dpb wrote:
>> ...
>>
>> > function [rss,y]=sample(Blink,AID,SID)
>> > idCh = [0 0; 0 1; 1 0; 1 1]; % a convenient array for chnls
>> ...
>>
>> > ixCh=ismember([S.AnchorChannel S.SourceChannel],idCh(j),'rows');
>> > rss(:,j)= -(33+S.agc*(89-33)/(29-1));
>> > end
>> ...
>>
>> Oops, left out the indexing vector after going to all the trouble to
>> generate it...
>>
>> rss(:,j)= -(33+S(ixCh).agc*(89-33)/(29-1));
>>
>> --
>
>
>
> it pops an error like this
>
> ??? Error using ==> ismember at 184
> A and S must have the same number of columns.
>
> Error in ==> samplefunction at 9
> ixCh=ismember([S(j).AnchorChannel S(j).SourceChannel],idCh(j),'rows');
>
>
> Actually I use S(j) becaz it can collect the values from J.

There shouldn't be a 'j' subscript on S -- ISMEMBER will return a column
logical vector of all rows matching the j_th_ condition in the idCh
array which is one of the four conditions on each pass. The j loop is
now 1:4, not the length.

The error message is puzzling, though--isn't S.[A..|S..]Channel a single
value so the quantity [S(j).AnchorChannel S(j).SourceChannel] ought to
be a 2-column array that is the same as the idCh array defined? If
that's not so, need definition of what those fields contain.

--

Subject: How to automatically loop over the combinations

From: Roy

Date: 19 Apr, 2013 15:17:09

Message: 11 of 28


> There shouldn't be a 'j' subscript on S -- ISMEMBER will return a column
> logical vector of all rows matching the j_th_ condition in the idCh
> array which is one of the four conditions on each pass. The j loop is
> now 1:4, not the length.
>
> The error message is puzzling, though--isn't S.[A..|S..]Channel a single
> value so the quantity [S(j).AnchorChannel S(j).SourceChannel] ought to
> be a 2-column array that is the same as the idCh array defined? If
> that's not so, need definition of what those fields contain.
>
> --

In my workspace you can find a Blink with size <500x1> so when we access the variable editor window we can find something like this (i,e) <500x1 cell array> inside which it contains <6x1 struct> ,<10x1 struct> ... <15x1 struct> inside these struct contains the information on Blinks from tags such as Soerce(Tag) ID Anchor ID AGC values anchor channel source channel etc.
 
Basically what my code does is it gets a input from the user for example if I specify ANCHOR ID=30, sOURCE(tag) ID=50 it will goes inside these <500x1 cell array> and check if there are values matching to my input and collect their agc values to calculate the mean rssi values.

Note: there are several anchor ID = 30,50,... 57
source id(tags id)=30,50,...57 (similar to anchor ID)

My aim is to match every combination of this anchor and source id and with different paris of anchor and source channel ((0,0),(0,1),(1,0),(1,1)) and give their mean rssi values. and if incase the anchorid and sourceID does not match it will simply return a NaN .

I hope you have a basic idea of what is actually happening.

Cheers,
Roy

Subject: How to automatically loop over the combinations

From: dpb

Date: 19 Apr, 2013 17:00:23

Message: 12 of 28

On 4/19/2013 10:17 AM, Roy wrote:
>
>> There shouldn't be a 'j' subscript on S -- ISMEMBER will return a
>> column logical vector of all rows matching the j_th_ condition in the
>> idCh array which is one of the four conditions on each pass. The j
>> loop is now 1:4, not the length.
>>
>> The error message is puzzling, though--isn't S.[A..|S..]Channel a
>> single value so the quantity [S(j).AnchorChannel S(j).SourceChannel]
>> ought to be a 2-column array that is the same as the idCh array
>> defined? If that's not so, need definition of what those fields contain.
>>
...

> In my workspace you can find a Blink with size <500x1> so when we access
> the variable editor window we can find something like this (i,e) <500x1
> cell array> inside which it contains <6x1 struct> ,<10x1 struct> ...
> <15x1 struct> inside these struct contains the information on Blinks
> from tags such as Soerce(Tag) ID Anchor ID AGC values anchor channel
> source channel etc.
>
> Basically what my code does is it gets a input from the user for example
> if I specify ANCHOR ID=30, sOURCE(tag) ID=50 it will goes inside these
> <500x1 cell array> and check if there are values matching to my input
> and collect their agc values to calculate the mean rssi values.
>
> Note: there are several anchor ID = 30,50,... 57
> source id(tags id)=30,50,...57 (similar to anchor ID)
>
> My aim is to match every combination of this anchor and source id and
> with different paris of anchor and source channel
> ((0,0),(0,1),(1,0),(1,1)) and give their mean rssi values. and if incase
> the anchorid and sourceID does not match it will simply return a NaN .
>
> I hope you have a basic idea of what is actually happening.

Need more than "a basic idea" to get anywhere--we'll get to the multiple
matching but got to have a specific definition of the inputs to do so.

OK, S.AID and S.SID are arrays of IDs, correct? IIUC they are actually
identical lists but if not you're really only concerned w/ the members
that interesect both, correct?

Now, let's move on to S.A and S.S channel. These are the fields that
contain the coded [0 1] values. Are these also arrays (vectors) and if
so are they row or column?

Can't solve your question w/o knowing what the data structure is,
specifically.

I'm looking to reduce the complexity of the inner portion first so can
apply that to the larger question more simply....

In the end this should boil down to a very concise computation I'm
virtually positive but have got to have the data structure down to get
there from here...

--

Subject: How to automatically loop over the combinations

From: dpb

Date: 19 Apr, 2013 17:05:56

Message: 13 of 28

On 4/19/2013 2:25 AM, Roy wrote:
...

> Well I would like to see the same I have pasted my result or is there
> any better ways to do ?

I'm working on that...I'm pretty sure there is a better way--see the
followup on the details of the data structure elsewhere in thread.
Perhaps the problem in the previous code is that I assumed row instead
of column vectors for the channel ID; your response to questions thereto
should clear that up.

--

Subject: How to automatically loop over the combinations

From: Roy

Date: 19 Apr, 2013 21:10:09

Message: 14 of 28


> Need more than "a basic idea" to get anywhere--we'll get to the multiple
> matching but got to have a specific definition of the inputs to do so.
>
> OK, S.AID and S.SID are arrays of IDs, correct? IIUC they are actually
> identical lists but if not you're really only concerned w/ the members
> that interesect both, correct?

Yes only if they match with eachother then the AGC values can be extracted and the rssi values will be calculated


>
> Now, let's move on to S.A and S.S channel. These are the fields that
> contain the coded [0 1] values. Are these also arrays (vectors) and if
> so are they row or column?
>

Once you run the program you can find Blink in my workspace.
Blink consists of <500x1 cell array> . when you access this cell array there are random structures as <6x1 struct> <10x1 struct> ..... <9x1 struct>( untill the 500 rows and 1 column). Inside this struct take for example <6x1 struct>,inside this struct you can find another set of structures like <1x1 struct><1x1 struct>....<1X1 struct> (untill 6 rows and 1 column) these are the blinks. Inside this blink(when there is a report between a anchor and source) contains the information on source ID anchor ID anchor Channel Source Channel agc values.

Actually they are not present in the form of array or row or column. The S.A and S.S channel are inside the blink which contains the information on Anchor ID source ID Anchor Channel Source Channel.It is just an information about the Blinks from ID thats it.What basically the code should do is go inside this information and see if the ID combination is present,if it is present then the anchor channel and source channel should be checked like the combination I have mentioned .

> Can't solve your question w/o knowing what the data structure is,
> specifically.
>
> I'm looking to reduce the complexity of the inner portion first so can
> apply that to the larger question more simply....
>
> In the end this should boil down to a very concise computation I'm
> virtually positive but have got to have the data structure down to get
> there from here...
>
> --

actually I could post the code but then there are over 30 files and its 14 MB .

Subject: How to automatically loop over the combinations

From: dpb

Date: 19 Apr, 2013 23:37:35

Message: 15 of 28

On 4/19/2013 4:10 PM, Roy wrote:
...

>> OK, S.AID and S.SID are arrays of IDs, correct? IIUC they are actually
>> identical lists but if not you're really only concerned w/ the members
>> that interesect both, correct?
>
> Yes only if they match with eachother then the AGC values can be
> extracted and the rssi values will be calculated
>
OK, that's one piece of the puzzle...

>> Now, let's move on to S.A and S.S channel. These are the fields that
>> contain the coded [0 1] values. Are these also arrays (vectors) and if
>> so are they row or column?
>>
>
> Once you run the program you can find Blink in my workspace.
> Blink consists of <500x1 cell array> .
> when you access this cell array
> there are random structures as <6x1 struct> <10x1 struct> ..... <9x1
> struct>( untill the 500 rows and 1 column). Inside this struct take for
> example <6x1 struct>,inside this struct you can find another set of
> structures like <1x1 struct><1x1 struct>....<1X1 struct> (until 6 rows
> and 1 column) these are the blinks. Inside this blink(when there is a
> report between a anchor and source) contains the information on source
> ID anchor ID anchor Channel Source Channel agc values.

I think this part is immaterial...ID

> Actually they are not present in the form of array or row or column. The
> S.A and S.S channel are inside the blink which contains the information
> on Anchor ID source ID Anchor Channel Source Channel.It is just an
> information about the Blinks from ID thats it.What basically the code
> should do is go inside this information and see if the ID combination is
> present,if it is present then the anchor channel and source channel
> should be checked like the combination I have mentioned .

Well, in the function you posted, you address each element of it as

S=cell2mat(Blink(i));
   for j=1:length(S)
    if S(j).AID==AID && S(j).SID==SID

which converts the element of the cell array Blink to an array of
structure and then you address each element of that field AID and SID
and compare them to constants. Hence S(j).AID must be an an element.

What I'm trying to find out is the structure/shape content of S.AID and
S.SID at that point because that's what need to operate on to do the
computation...

>> Can't solve your question w/o knowing what the data structure is,
>> specifically.
>>
>> I'm looking to reduce the complexity of the inner portion first so can
>> apply that to the larger question more simply....
>>
>> In the end this should boil down to a very concise computation I'm
>> virtually positive but have got to have the data structure down to get
>> there from here...
>>
> actually I could post the code but then there are over 30 files and its
> 14 MB .

All I need I believe is the structure of S.AID and S.SID so I can figure
out why what I wrote before doesn't seem to work...

--

Subject: How to automatically loop over the combinations

From: Roy

Date: 20 Apr, 2013 16:02:16

Message: 16 of 28

 >> Now, let's move on to S.A and S.S channel. These are the fields that
> >> contain the coded [0 1] values. Are these also arrays (vectors) and if
> >> so are they row or column?
> >>
> >
> > Once you run the program you can find Blink in my workspace.
> > Blink consists of <500x1 cell array> .
> > when you access this cell array
> > there are random structures as <6x1 struct> <10x1 struct> ..... <9x1
> > struct>( untill the 500 rows and 1 column). Inside this struct take for
> > example <6x1 struct>,inside this struct you can find another set of
> > structures like <1x1 struct><1x1 struct>....<1X1 struct> (until 6 rows
> > and 1 column) these are the blinks. Inside this blink(when there is a
> > report between a anchor and source) contains the information on source
> > ID anchor ID anchor Channel Source Channel agc values.
>
> I think this part is immaterial...ID

maybe it is immaterial but this is where the information are extracted I suppose.I wanted to make it clear for you.

> > Actually they are not present in the form of array or row or column. The
> > S.A and S.S channel are inside the blink which contains the information
> > on Anchor ID source ID Anchor Channel Source Channel.It is just an
> > information about the Blinks from ID thats it.What basically the code
> > should do is go inside this information and see if the ID combination is
> > present,if it is present then the anchor channel and source channel
> > should be checked like the combination I have mentioned .
>
> Well, in the function you posted, you address each element of it as
>
> S=cell2mat(Blink(i));
> for j=1:length(S)
> if S(j).AID==AID && S(j).SID==SID
>
> which converts the element of the cell array Blink to an array of
> structure and then you address each element of that field AID and SID
> and compare them to constants. Hence S(j).AID must be an an element.

actually if I use the cell2mat (actually the length of Blink is <1561x1> so when I use this in the command window it returns as follows

cell2mat(BlinkSetList)

ans =

18402x1 struct array with fields:
    ServerTime
    TOA
    AnchorID
    AnchorChan
    AnchorNumb
    blinkID
    SourceID
    SourceChan
    TimeB
    agc



> What I'm trying to find out is the structure/shape content of S.AID and
> S.SID at that point because that's what need to operate on to do the
> computation...
>
 All I need I believe is the structure of S.AID and S.SID so I can figure
> out why what I wrote before doesn't seem to work...
>

This part I quite did not understand ! do you want the code or some thing from the workspace or variable editor window so that I can work on that and post it here.

 

Subject: How to automatically loop over the combinations

From: dpb

Date: 20 Apr, 2013 16:39:09

Message: 17 of 28

On 4/20/2013 11:02 AM, Roy wrote:
...

...[I wrote; prior attributions elided]...

>> Well, in the function you posted, you address each element of it as
>>
>> S=cell2mat(Blink(i));
>> for j=1:length(S)
>> if S(j).AID==AID && S(j).SID==SID
>>
>> which converts the element of the cell array Blink to an array of
>> structure and then you address each element of that field AID and SID
>> and compare them to constants. Hence S(j).AID must be an an element.
>
> actually if I use the cell2mat (actually the length of Blink is <1561x1>
> so when I use this in the command window it returns as follows
>
> cell2mat(BlinkSetList)
>
> ans =
> 18402x1 struct array with fields:
> ServerTime
> TOA
> AnchorID
> AnchorChan
> AnchorNumb
> blinkID
> SourceID
> SourceChan
> TimeB
> agc
>

Right...that part I've got.

>> What I'm trying to find out is the structure/shape content of S.AID
>> and S.SID at that point because that's what need to operate on to do
>> the computation...
>>
> All I need I believe is the structure of S.AID and S.SID so I can figure
>> out why what I wrote before doesn't seem to work...
>>
>
> This part I quite did not understand ! do you want the code or some
> thing from the workspace or variable editor window so that I can work on
> that and post it here.

OK, now I am confused...your code is written as

if S(j).AID==AID && S(j).SID==SID

but there is no field AID in S. What is AID?

I was assuming that the above would return sotoo


 > cell2mat(BlinkSetList)
 >
 > ans =
 > 18402x1 struct array with fields:
 > ServerTime
 > TOA
 > AID
 > AnchorChan
 > AnchorNumb
 > blinkID
 > SID
 > SourceChan
 > TimeB
 > agc

So what I was asking for was what

A=S.AID;
whos A

and likewise for SID returns.

Since the field names aren't consistent w/ the code I don't know what
the code is doing...

--

Subject: How to automatically loop over the combinations

From: Roy

Date: 20 Apr, 2013 17:18:11

Message: 18 of 28

 >> What I'm trying to find out is the structure/shape content of S.AID
> >> and S.SID at that point because that's what need to operate on to do
> >> the computation...
> >>
> > All I need I believe is the structure of S.AID and S.SID so I can figure
> >> out why what I wrote before doesn't seem to work...
> >>
> >
> > This part I quite did not understand ! do you want the code or some
> > thing from the workspace or variable editor window so that I can work on
> > that and post it here.
>
> OK, now I am confused...your code is written as
>
> if S(j).AID==AID && S(j).SID==SID
>
> but there is no field AID in S. What is AID?
>
> I was assuming that the above would return sotoo
>
>
> > cell2mat(BlinkSetList)
> >
> > ans =
> > 18402x1 struct array with fields:
> > ServerTime
> > TOA
> > AID
> > AnchorChan
> > AnchorNumb
> > blinkID
> > SID
> > SourceChan
> > TimeB
> > agc
>
> So what I was asking for was what
>
> A=S.AID;
> whos A
>
> and likewise for SID returns.
>
> Since the field names aren't consistent w/ the code I don't know what
> the code is doing...
>
> --



when I typed in "who" it listed me as follows

Your variables are:

AnchorDevs PI gAirC gSubset rssi_dBm2 y1
AnchorID PacerDevs gBatchMode gSubsetTag rssi_dBm3 y2
BlinkSetList SourceID gCP gWorkDir rssi_dBm4 y3
MeasurementDir gAI gScenario rssi_dBm1 t_interval y4

>> AnchorDevs

AnchorDevs =

1x20 struct array with fields:
    ID
    x
    y
    channels

>> AnchorID

AnchorID =

    30


Actually inside this AnchorDevs in workspace you can find the AnchorID in the forms of columns with the AnchorID present inside.And PacerDevs is same as AnchorDevs it contains the same details inside too

Subject: How to automatically loop over the combinations

From: Roy

Date: 20 Apr, 2013 17:39:10

Message: 19 of 28

> > A=S.AID;
> > whos A
> >
> > and likewise for SID returns.
> >
> > Since the field names aren't consistent w/ the code I don't know what
> > the code is doing...
> >
> > --
>
>
>
> when I typed in "who" it listed me as follows
>
> Your variables are:
>
> AnchorDevs PI gAirC gSubset rssi_dBm2 y1
> AnchorID PacerDevs gBatchMode gSubsetTag rssi_dBm3 y2
> BlinkSetList SourceID gCP gWorkDir rssi_dBm4 y3
> MeasurementDir gAI gScenario rssi_dBm1 t_interval y4
>
> >> AnchorDevs
>
> AnchorDevs =
>
> 1x20 struct array with fields:
> ID
> x
> y
> channels
>
> >> AnchorID
>
> AnchorID =
>
> 30
>
>
> Actually inside this AnchorDevs in workspace you can find the AnchorID in the forms of columns with the AnchorID present inside.And PacerDevs is same as AnchorDevs it contains the same details inside too


AnchorDevs contains around 20 random AnchorID's in the form of columns (i.e) <1x20 struct> and same with pacerDevs. they are also identical. I assume PacerDevs is the sourceID.

Actually why i am mentioning it as SourceID is because when you access through the BlinkSetList via the variable editor window you will find the information on the Blink.Which I earlier posted you about the details it will contain in it

Note: Actually it is BlinkSetList. Just to post in the forum I wrote as Blink.

when you access the BlinkSetList via the command window you will get as

BlinkSetList{1,1}(1,1)

ans =

    ServerTime: 0.0308
           TOA: 4.4846e-005
      AnchorID: 53
    AnchorChan: 1
    AnchorNumb: 8
       blinkID: 131
      SourceID: 57
    SourceChan: 1
         TimeB: 1.1373e+005
           agc: 21

Note: you can access the BlinkSetList via mentioning its position of rows and not with the structure. It has nothing to do with the struct.

an example is

 BlinkSetList{1561,1}(1,1)

ans =

    ServerTime: 19.9166
           TOA: 1.3511e-005
      AnchorID: 1476
    AnchorChan: 1
    AnchorNumb: 26
       blinkID: 149
      SourceID: 1519
    SourceChan: 1
         TimeB: 3.0406e+004
           agc: 20

another example is

BlinkSetList{1561,1}(2,1)

ans =

    ServerTime: 19.9166
           TOA: 1.1481e-005
      AnchorID: 1518
    AnchorChan: 1
    AnchorNumb: 28
       blinkID: 149
      SourceID: 1519
    SourceChan: 1
         TimeB: 3.0323e+004
           agc: 19


Hope these details is enough to figure out

Subject: How to automatically loop over the combinations

From: dpb

Date: 20 Apr, 2013 17:49:35

Message: 20 of 28

On 4/20/2013 12:18 PM, Roy wrote:
> >> What I'm trying to find out is the structure/shape content of S.AID
>> >> and S.SID at that point because that's what need to operate on to do
>> >> the computation...
>> >>
>> > All I need I believe is the structure of S.AID and S.SID so I can
>> figure
>> >> out why what I wrote before doesn't seem to work...
>> >>
>> >
>> > This part I quite did not understand ! do you want the code or some
>> > thing from the workspace or variable editor window so that I can
>> work on
>> > that and post it here.
>>
>> OK, now I am confused...your code is written as
>>
>> if S(j).AID==AID && S(j).SID==SID
>>
>> but there is no field AID in S. What is AID?
>>
>> I was assuming that the above would return sotoo
>>
>>
>> > cell2mat(BlinkSetList)
>> >
>> > ans =
>> > 18402x1 struct array with fields:
>> > ServerTime
>> > TOA
>> > AID
>> > AnchorChan
>> > AnchorNumb
>> > blinkID
>> > SID
>> > SourceChan
>> > TimeB
>> > agc
>>
>> So what I was asking for was what
>>
>> A=S.AID;
>> whos A
>>
>> and likewise for SID returns.
>>
>> Since the field names aren't consistent w/ the code I don't know what
>> the code is doing...
>>
...

'who' in what context? The workspace? That's of no interest/help.

> when I typed in "who" it listed me as follows
...

> Actually inside this AnchorDevs in workspace you can find the AnchorID
> in the forms of columns with the AnchorID present inside.And PacerDevs
> is same as AnchorDevs it contains the same details inside too

Again, it's the internals of the Blink structure element that you expand
into the S array inside the function that's what's of significance--the
rest is just confusing fluff at the moment.

I'm beginning to gather you didn't write this code so you don't
understand at all what you're looking at which doesn't help, but...

What you need to do is set a breakpoint after the S=cell2mat() call in
the function sample and while in _that_ context at the command line look
at the structure fields there.

_THAT'S_ the structure that is being operated on in the function and
what we need to know what is...

Surely you can see that the call to the function as you posted in the
original post of

AID=30;
SID=50;
[rss_dBm1,...,rss_dBm4,y1,...,y4]=sample(Blink,AID,SID)

where the function definition line is then given as

function [rss_dBm1...,y4]=sample(Blink,AID,SID)

and then the above-quoted line of referencing the structure S w/ the
field name .AID is a problem if there isn't a field named AID inside it
since the variable AID is passed as an integer, not a character variable
referencing a named field is peculiar at best and simply wrong at worst.
  I guess now is an appropriate time to ask if the above function
actually runs w/o error?

--

Subject: How to automatically loop over the combinations

From: dpb

Date: 20 Apr, 2013 18:02:35

Message: 21 of 28

On 4/20/2013 12:49 PM, dpb wrote:
...

> Surely you can see that the call to the function as you posted in the
> original post of
>
> AID=30;
> SID=50;
> [rss_dBm1,...,rss_dBm4,y1,...,y4]=sample(Blink,AID,SID)
>
> where the function definition line is then given as
>
> function [rss_dBm1...,y4]=sample(Blink,AID,SID)
>
> and then the above-quoted line of referencing the structure S w/ the
> field name .AID is a problem if there isn't a field named AID inside it
> since the variable AID is passed as an integer, not a character variable
> referencing a named field...

And even the latter is a problem because the syntax isn't correct to use
a variable name as the fieldname...

--

Subject: How to automatically loop over the combinations

From: dpb

Date: 20 Apr, 2013 18:14:07

Message: 22 of 28

On 4/20/2013 12:39 PM, Roy wrote:
...

> Hope these details is enough to figure out

Lots of details; unfortunately, they're not the pertinent ones...

I've taken the liberty to send an e-mail to your address; w/ a specific
request. If you care to followup I'll look at the code/data directly
and see if can figure out what's going on here...

--dpb

--

Subject: How to automatically loop over the combinations

From: Roy

Date: 20 Apr, 2013 18:30:10

Message: 23 of 28

dpb <none@non.net> wrote in message <kkul7l$uae$1@speranza.aioe.org>...
> On 4/20/2013 12:49 PM, dpb wrote:
> ...
>
> > Surely you can see that the call to the function as you posted in the
> > original post of
> >
> > AID=30;
> > SID=50;
> > [rss_dBm1,...,rss_dBm4,y1,...,y4]=sample(Blink,AID,SID)
> >
> > where the function definition line is then given as
> >
> > function [rss_dBm1...,y4]=sample(Blink,AID,SID)
> >
> > and then the above-quoted line of referencing the structure S w/ the
> > field name .AID is a problem if there isn't a field named AID inside it
> > since the variable AID is passed as an integer, not a character variable
> > referencing a named field...
>
> And even the latter is a problem because the syntax isn't correct to use
> a variable name as the fieldname...
>
> --
 
My email id is theredhat33@yahoo.com. we can discuss there.

Subject: How to automatically loop over the combinations

From: Roy

Date: 20 Apr, 2013 18:35:17

Message: 24 of 28

dpb <none@non.net> wrote in message <kkult8$dn$1@speranza.aioe.org>...
> On 4/20/2013 12:39 PM, Roy wrote:
> ...
>
> > Hope these details is enough to figure out
>
> Lots of details; unfortunately, they're not the pertinent ones...
>
> I've taken the liberty to send an e-mail to your address; w/ a specific
> request. If you care to followup I'll look at the code/data directly
> and see if can figure out what's going on here...
>
> --dpb
>
> --


my email id is theredhat33@yahoo.com

Subject: How to automatically loop over the combinations

From: Roy

Date: 20 Apr, 2013 18:59:16

Message: 25 of 28

"Roy" wrote in message <kkun55$qo5$1@newscl01ah.mathworks.com>...
> dpb <none@non.net> wrote in message <kkult8$dn$1@speranza.aioe.org>...
> > On 4/20/2013 12:39 PM, Roy wrote:
> > ...
> >
> > > Hope these details is enough to figure out
> >
> > Lots of details; unfortunately, they're not the pertinent ones...
> >
> > I've taken the liberty to send an e-mail to your address; w/ a specific
> > request. If you care to followup I'll look at the code/data directly
> > and see if can figure out what's going on here...
> >
> > --dpb
> >
> > --
>
>
> my email id is theredhat33@yahoo.com


hello did you receive my email id ?

Subject: How to automatically loop over the combinations

From: Roy

Date: 20 Apr, 2013 20:21:10

Message: 26 of 28

"Roy" wrote in message <kkun55$qo5$1@newscl01ah.mathworks.com>...
> dpb <none@non.net> wrote in message <kkult8$dn$1@speranza.aioe.org>...
> > On 4/20/2013 12:39 PM, Roy wrote:
> > ...
> >
> > > Hope these details is enough to figure out
> >
> > Lots of details; unfortunately, they're not the pertinent ones...
> >
> > I've taken the liberty to send an e-mail to your address; w/ a specific
> > request. If you care to followup I'll look at the code/data directly
> > and see if can figure out what's going on here...
> >
> > --dpb
> >
> > --
>
>
> my email id is theredhat33@yahoo.com


I have put up my email id for you to contact !!!

Subject: How to automatically loop over the combinations

From: dpb

Date: 20 Apr, 2013 21:50:21

Message: 27 of 28

On 4/20/2013 3:21 PM, Roy wrote:
...

> I have put up my email id for you to contact !!!

Done; as noted in the note, actually I'm a farmer so had to spend the
afternoon doing other things for the most part...

--

Subject: How to automatically loop over the combinations

From: dpb

Date: 22 Apr, 2013 14:30:19

Message: 28 of 28

On 4/19/2013 2:39 AM, Roy wrote:
> dpb <none@non.net> wrote in message <kkptvb$cf2$1@speranza.aioe.org>...
>> On 4/18/2013 5:07 PM, dpb wrote:
...
>> Oops, left out the indexing vector after going to all the trouble to
>> generate it...
>>
>> rss(:,j)= -(33+S(ixCh).agc*(89-33)/(29-1));
>>
...
> it pops an error like this
>
> ??? Error using ==> ismember at 184
> A and S must have the same number of columns.
>
> Error in ==> samplefunction at 9
> ixCh=ismember([S(j).AnchorChannel S(j).SourceChannel],idCh(j),'rows');
>
...

For completeness on this thread--

Roy supplied a sample offline that resolves the problems w/ the
structure names and organization and a function that seems to replace
his multiple loops is

function rss=sample(Blink,AID,SID)
% compute the RSS and STD values
% column 1-4 --> 0 0, 0 1, 1 0, 1 1 for channels

   rss=nan(length(Blink),4); % initialize the array to NaN
   y=nan(length(Blink),4);
   for i=1:length(Blink)
     S=cell2mat(Blink(i));

     % positions of matching IDs
     idxID = find([[S.AnchorID]'==AID & [S.SourceID]'==SID]);
     if isempty(idxID), continue, end % if none satisfy, go on...

     % index into jss based on channel
     jdx = [S(idxID).AnchorChan]'*2 + [S(idxID).SourceChan]'+1;
     idx=sub2ind(size(rss),ones(length(jdx),1).*i, jdx);
     rss(idx)= -(33+[S(idxID).agc]'*(89-33)/(29-1));
   end
   % remove unused rows
   rss(all(isnan(rss),2),:)=[];
end

Where I went wrong earlier was forgetting that the expression
S(:).FieldName returns a comma-separated list so didn't include the
square brackets to assemble the results into vectors. The above also
eliminates the previous inner loop over the four channel combinations by
computing the column index directly from the channel values and then
fills the RSS array.

I've not delved into the next higher level of abstraction of trying to
operate on the array of structures overall waiting for confirmation from
Roy that the above is what he was looking for for results for sure...

--

Tags for 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