新版本:
主程序及功能编辑部分
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 [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)]);
我得到输出,然后是错误
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......
.
.
.
???未定义的函数或变量“rss_dB1”。==> arrayfun 中的错误 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)
但我希望我的结果为
所有组合的结果,例如: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
注意:有时通道对组合或 AID 和 SID 组合不存在,所以在这种情况下它只是返回 NaN(这就是我使用 isempty 的原因)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
首先,我感谢看到这篇文章并尝试提供解决方案的人。在此先感谢
我的问题如下,
主程序的一部分
AID=30;
SID=50;
[rss_dBm1,rss_dBm2,rss_dBm3,rss_dBm4,y1,y2,y3,y4]=sample(Blink,AID,SID)
注意:AID 有不同的 ID 为 30,50,52,54,55,57(与 SID 相同) SID 有不同的 ID 为 30,50,52,54,55,57(与 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.
调用函数
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)]);
现在我的问题是如何在不给用户输入的情况下自动检查 AID 和 SID 的不同组合?如果这有意义,它应该遍历每个组合并返回 AID SID 与锚通道和源通道的所有可能组合的“rss”结果
一种组合的结果: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
以上是一个 AID(30) SID(50) 组合的结果。但我想像 AID=50 SID=52, AID=52 SID=55, AID=57 SID=54 这样循环,所以这些是一些示例对。我希望结果像上面的输出,除了它还应该包括我提到的对,有四种不同的通道组合
注意:上述组合的输出也必须包含在下面提到的组合中。示例:AID=50 SID=52,AID=52 SID=55,AID=57 SID=54 带锚点,源通道对 (0,0),(0,1),(1,0),(1,1 ) 在少数情况下,锚源通道对不存在,因此它会自动返回“0”或“NaN”