New version:
The Edited Part of main program and function
AID=[30,50,52,53,54,56,57,72,75,77];
SID=[30,50,52,53,54,56,57,72,75,77];
[AID,SID]=meshgrid(AID,SID)
myfunction=@(SID,AID)myfunc(Blink,SID,AID);
[rss_dBm1,rss_dBm2,rss_dBm3,rss_dBm4,y1,y2,y3,y4]=arrayfun(Blink,AID,SID)
Function
function [rss_dBm1,rss_dBm2,rss_dBm3,rss_dBm4,y1,y2,y3,y4] = arrayfun(Blink,AID,SID)
for i=1:length(BlinkSetList)
S=cell2mat(BlinkSetList(i));
for j=1:length(S)
if S(j).AID==AID & S(j).SID==SID
if S(j).AnchorChan==0 & S(j).SourceChan==0
y=S(j).agc;
rss_dB1(i)= -(33+y*(89-33)/(29-1));
else
rss_dB1(i)=0;
isempty(rss_dB1(i))
end
if S(j).AnchorChan==0 & S(j).SourceChan==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).AnchorChan==1 & S(j).SourceChan==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 rssi value with A-Chan 0 and S-Chan 0 is %0.0f',rss_dBm1)]);
disp([sprintf('The rssi value with A-Chan 0 and S-Chan 1 is %0.0f',rss_dBm2)]);
disp([sprintf('The rssi value with A-Chan 1 and S-Chan 0 is %0.0f',rss_dBm3)]);
disp([sprintf('The rssi value with A-Chan 1 and S-Chan 1 is %0.0f',rss_dBm4)]);
and I get output followed by the error as
AID =
Columns 1 through 10
30 50 52........
30 50 52
30 50 52
.
.
SID =
Columns 1 through 10
30 30 30
50 50 50
52 52 52......
.
.
.
??? Undefined function or variable "rss_dB1". Error in ==> arrayfun at 54 rss_dB1(rss_dB1==0)=[];
Error in ==> main_reduced at 38
[rss_dBm1,rss_dBm2,rss_dBm3,rss_dBm4,y1,y2,y3,y4]=arrayfun(Blink,AID,SID)
but I want my result as
Result for all combinations for example: AID=30 SID=50 , AID=50 SID=54 , AID= 54 SID=57 .......
The rss value with A-Chan 0 and S-Chan 0 is -68 % combination of AID=30 SID=50
The rss value with A-Chan 0 and S-Chan 1 is -73 % with all pairs of anchor and source channel (0,0),(0,1),(1,0),(1,1)
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
The rss value with A-Chan 0 and S-Chan 0 is -68 % combination of AID=50 SID=54
The rss value with A-Chan 0 and S-Chan 1 is -73% with all pairs of anchor and source channel (0,0),(0,1),(1,0),(1,1)
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
The rss value with A-Chan 0 and S-Chan 0 is -68 % combination of AID=54 SID=57
The rss value with A-Chan 0 and S-Chan 1 is -73 % with all pairs of anchor and source channel (0,0),(0,1),(1,0),(1,1)
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
rss_dBm1 =-68
rss_dBm2 =-72.8621
rss_dBm3 =-73
rss_dBm4 = -76
rss_dBm1 =-68
rss_dBm2 =-72.8621
rss_dBm3 =-73
rss_dBm4 = -76
Note : At times the channel pair combinations or AID & SID combinations does not exist, so in that case it is simply returns NaN ( that's why I used isempty)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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 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 problem 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 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 like AID=50 SID=52, AID=52 SID=55, AID=57 SID=54 so these are some examples of the pairs. I want the result to be like the above output, except it should also include the pairs I mentioned ,with four different channel combinations
Note:The output with above combination must also be included with below mentioned combinations too. example:AID=50 SID=52,AID=52 SID=55,AID=57 SID=54 with anchor,source channel pairs (0,0),(0,1),(1,0),(1,1) in few cases the anchor source channel pairs does not exist so then it automatically returns '0'or'NaN'