2017-03-03 36 views
-1

在我的程序的這一部分,我想給ID變量分配到RealTagID變量。然後在第二部分我想的ID變量分配到RealTagID_NEW。 ID變量來自我的測量數據,我已經在下面上傳了它(它來自EPC)。它不工作,我怎麼想,監守在Matlab的9B和BB是由於某種原因,在第一部分中一樣的...爲什麼在我的Matlab程序中,ismember不能正常工作?

這裏是我的代碼:

close all 
clc 

RealTagID=['A3 ' ;'A1 ' ; '9F ' ;'9D ' ; '9B ' ; 'A9 ' ; 'A7 ' ; 'A5 ' ]; 
%The last two characters of the EPC code of the tags 
RealPOSX=[40 31 0 -31 -40 -32 0 +31]; 
%The x positions of fixed tags 
RealPosY=[0 27 40 27 0 -27 -40 -27]; 
% The y positions of fixed tags 

for i=1:length(XLocalization) 
    temp=Epc{i}; 
    ID(i,:)=temp(end-2:end); 
    %Makes a new variable, called 'ID', which is the last two characters from 
    %the measured EPC codes 
end 

for i =1 :length(RealPOSX) 

    idx = all(ismember(ID,RealTagID(i,:)),2) 
    pos=find(idx==1); 
    POS{i}=pos; 
end 
%------------------------------------------------------------------------------------------------------------------------------- 

RealPOSX_NEW=[20 17 0 -17 -20 -17 0 17]; 
%The x positions of fixed tags 
RealPosY_NEW=[0 12 20 12 0 -12 -20 -12]; 
% The y positions of fixed tags 
RealTagID_NEW=['B3 ' ;'B5 ' ; 'B7 ' ;'BB ' ; 'AD ' ; 'AB ' ; 'AF ' ; 'B1 ' ]; 
%The last two characters of the EPC code of the tags 

for i =1 :length(RealPOSX_NEW) 
    idxx = all(ismember(ID,RealTagID_NEW(i,:)),2) 
    poss=find(idxx==1); 
    POSS{i}=poss; 


end 

第二部分,它甚至值得。在這種情況下,B1等於BB,B3與BB,B5與BB,B7與BB,AB與BB。

我想對它們進行比較,如果它們是相同的,那麼我們是合乎邏輯的1如果沒有的話0。但它不工作,因爲這個BB變量的那樣,否則我不知道。

我使用ismember功能,但它似乎不是最好的選擇。任何想法?我應該使用什麼?

所以我的目標是使POS和POSS變量相等,這意味着所有的人都應該是一個1×8細胞和具有細胞每58元。現在它們中的一些有116個,因爲在這種情況下,對於BB而言,BB也等於9B,B1,B3,B5,B7,B9。所以它不是那麼好,BB應該和BB一樣,不要和其他變量一樣。

這裏是我的測量Measurement

我希望你能幫助我,我花了我一天就可以了,沒有進展。

+0

我*認爲你遇到麻煩的原因是'BB'不是單個數組元素,它是一個包含2個元素的字符數組。 'ismember('BB','9B')'會顯示這個錯誤。除此之外,你的問題有很多多餘的信息,不能幫助我們回答你真正的問題,並且你的代碼不可執行,因爲你沒有定義好幾個變量。請提供你想要的結果[mcve]。 – beaker

+0

我很抱歉,我改正了!我僞造了第二個循環需要RealPOSX。我也欺騙了文本,希望現在我的問題更加清晰。 我認爲你是對的,但我仍然不知道如何解決問題。 – tiby007

+0

有人有什麼想法嗎? – tiby007

回答

0

最後我strfind解決它。 這是我的代碼,它的工作完美。

close all 
clc 
RealPOSX=[40 31 1 -31 -40 -32 1 +31]; 
%The x positions of fixed tags 
RealPosY=[1 27 40 27 1 -27 -40 -27]; 
% The y positions of fixed tags 
RealTagID=['A3 ' ;'A1 ' ; '9F ' ;'9D ' ; '9B ' ; 'A9 ' ; 'A7 ' ; 'A5 ' ]; 

for i=1:length(XLocalization) 
    temp=Epc{i}; 
    ID(i,:)=temp(end-2:end); 

end 



for i =1 :length(RealPOSX)   
    idx = strfind(string(ID), RealTagID(i,:)) 

    pos= find(not(cellfun('isempty', idx))) 
    POS{i}=pos; 
    end 

%------------------------------------------------------------------------------------------------------------------------------- 

RealPOSX_NEW=[20 17 0 -17 -20 -17 0 17]; 
%The x positions of fixed tags 
RealPosY_NEW=[0 12 20 12 0 -12 -20 -12]; 
% The y positions of fixed tags 
RealTagID_NEW=['B3 ' ;'B5 ' ; 'B7 ' ;'BB ' ; 'AD ' ; 'AB ' ; 'AF ' ; 'B1 ' ]; 
%The last two characters of the EPC code of the tags 

for i =1 :length(RealPOSX) 
    %idxx = all(ismember(ID,RealTagID_NEW(i,:)),2) 
    %poss=find(idxx==1); 
    idxx = strfind(string(ID), RealTagID_NEW(i,:)) 
    poss= find(not(cellfun('isempty', idxx))) 
    POSS{i}=poss; 
相關問題