2014-04-12 6 views
0

나는 표적과 matlab에 신경망 프로세스의 예상 값을 저장하기 위해 두 개의 세포를 사용하고 있습니다. 나는 각각 값을 저장하기 위해 2 개의 1 * 1 셀 어레이를 사용했다. 그리고 여기에 내 코드가있다.matlab에서 두 셀 요소를 비교하는 방법은 무엇입니까?

cinfo=cell(1,2) 
cinfo(1,1)=iter(1,10)%value is retrieved from a dataset iter 
cinfo(1,2)=iter(1,11) 
amp1=cinfo(1,1); 
amp2=cinfo(1,2); 
if amp1 == amp2 
     message=sprintf('NOT DETECTED BY THE DISEASE'); 
     uiwait(msgbox(message)); 

하지만 위의 코드를 실행하면 다음과 같은 오류 얻을 :

??? Undefined function or method 'eq' for input arguments of type 'cell'. 
Error in ==> comparison at line 38 
if amp1 == amp2 

어떻게이 문제를 해결하기를?

+1

[cellfun] (http://www.mathworks.in/help/matlab/ref/cellfun.html)을 탐색하고 거기에서 알아내는 것이 좋습니다. – Divakar

+0

@Divakar : 감사합니다. 그리고 나중에 저는 cellfun을 보았습니다. 그러나 cellfun을 사용하여 두 숫자를 비교할 수 있습니다. ? – user3368213

+0

숫자의 셀 배열이 있고 질문에 대한 답이 예입니다. – Divakar

답변

0

문제는 어떻게 색인을 생성했는지입니다. amp1amp2 위를 스칼라들이하지 않는 경우 행동 않습니다, 그러나

amp1=cinfo{1,1}; # get the actual element from the cell array, and not just a 
amp2=cinfo{1,2}; # 1x1 cell array by indexing with {} 
if (amp1 == amp2) 
    ## etc... 

: 1x1 크기의 셀 어레이 대신 중괄호와 색인에 의해, 단일 셀의 실제 요소를 얻을, 많은 이해가되지 않습니다 기묘한. 대신

if (all (amp1 == amp2)) 
    ## etc... 
0

isequal을 사용하십시오. 셀의 내용이 다른 크기 인 인 경우에도 작동합니다..

예 : 코드, amp1amp2는 숫자 벡터를 포함하는 하나의 세포로 구성된 세포 배열 인 평행이 예에서

cinfo=cell(1,2); 
cinfo(1,1) = {1:10}; %// store vector of 10 numbers in cell 1 
cinfo(1,2) = {1:20}; %// store vector of 20 numbers in cell 2 
amp1 = cinfo(1,1); %// single cell containing a length-10 numeric vector 
amp2 = cinfo(1,2); %// single cell containing a length-20 numeric vector 
if isequal(amp1,amp2) 
    %// ... 

. 또 다른 가능성은 직접 각 셀의 내용amp1, amp2에 저장 한 다음 전원을 비교하는 것입니다 : 벡터가 다른 가지고 있기 때문에 이러한 경우에도 비교 amp1==amp1 또는 all(amp1==amp2)이 오류를 줄 것이다

amp1 = cinfo{1,1}; %// length-10 numeric vector 
amp2 = cinfo{1,2}; %// length-20 numeric vector 
if isequal(amp1,amp2) 
    %// ... 

크기.

관련 문제