我有两个数组如下。
BLoc1 = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'I', 'K', 'L', 'M']
BLoc2 = ['A', 'D', 'E', 'F', 'G', 'I', 'J', 'K', 'L']
我希望输出如下。
BLoc1 = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'I', 'NA', 'K', 'L', 'M']
BLoc2 = ['A', 'NA', 'NA', 'D', 'E', 'F', 'G', 'I', 'J', 'K', 'L','NA']
答案 0 :(得分:1)
您尝试实现的结果仅适用于单元格数组,因为否则'NA'
将被视为'N' 'A'
,即两个字母表都位于不同的索引处。
无论如何,以下代码将帮助您做出决定: -
BLoc1 = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'I', 'K', 'L', 'M'];
BLoc2 = ['A', 'D', 'E', 'F', 'G', 'I', 'J', 'K', 'L'];
%Converting to cell arrays
BLoc1=num2cell(BLoc1,size(BLoc1,2));
BLoc2=num2cell(BLoc2,size(BLoc2,2));
%Union of the two
complete=union(BLoc1,BLoc2);
NewBLoc1=complete;
[~,idx]=ismember(complete,BLoc1);
idx = find(idx==0); %finding the indexes where BLoc1 has missing elements
[NewBLoc1{idx}]=deal('NA') %filling the elements at missing indexes with 'Na'
%Similarly for BLoc2
NewBLoc2=complete;
[~,idx]=ismember(complete,BLoc2);
idx = find(idx==0);
[NewBLoc2{idx}]=deal('NA')
%converting back to simple matrix since that's your requirement in the question
%but I recommend you to also run the code atleast once without the next two lines too.
NewBLoc1= cell2mat(NewBLoc1)
NewBLoc2= cell2mat(NewBLoc2)
答案 1 :(得分:-1)
检查一下:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>