From: YASMIN M. Yacob on 5 Aug 2010 01:43 Hi, Need help to compare elements in cell array; used isequal and several other ways but misleading. Cell array is a 20x2 dataset with 3 classes. Wants to compare if the class is the same then proceed to next position ( i.e m act as index) until find changing class else span/skip 6 places. 2nd column is the class. Thanks. load data load labels A=dataset(data,labels); [nobs,nvars] = getsize(A); B=cell(nobs,2); C=cell(nobs,2); E=cell(nobs,2); % Sort based on 1st column for i = 1 : nvars B = [A(:,i) A.labels]; %disp(B(:,1:2)); %works C = B(:,1:2); [D I]=sort(C(:,1),'ascend'); %works E=C(I,:); %works % comparing elements in cell array m = 6; while (m < nobs) tf = (E(m,2)== E(m+1,2)); %tf=isequal(E(m,2),E(m+1,2)); if (tf == 1) span=0; else span=5; end m = m + span + 1; end end Sample run/error: 20 by 2 dataset with 3 classes: [5 8 7] 4.3000 3.0000 4.4000 2.0000 4.6000 1.0000 4.6000 2.0000 4.7000 2.0000 4.8000 2.0000 4.8000 2.0000 4.9000 1.0000 4.9000 2.0000 5.0000 1.0000 5.0000 2.0000 5.1000 1.0000 5.1000 3.0000 5.1000 3.0000 5.4000 1.0000 5.4000 2.0000 5.4000 3.0000 5.7000 3.0000 5.7000 3.0000 5.8000 3.0000 ??? The following error occurred converting from dataset to logical: Undefined function or method 'logical' for input arguments of type 'dataset'. Error in ==> discretize5AUGpg at 24 if (tf == 1)
From: us on 5 Aug 2010 03:01 "YASMIN M. Yacob" <yasmin160273(a)yahoo.com> wrote in message <i3dj1b$lcs$1(a)fred.mathworks.com>... > Hi, > Need help to compare elements in cell array; used isequal and several other ways but misleading. Cell array is a 20x2 dataset with 3 classes. Wants to compare if the class is the same then proceed to next position ( i.e m act as index) until find changing class else span/skip 6 places. 2nd column is the class. > Thanks. > tf = (E(m,2)== E(m+1,2)); %tf=isequal(E(m,2),E(m+1,2)); > if (tf == 1) > ??? The following error occurred converting from dataset to logical: > Undefined function or method 'logical' for input arguments of type 'dataset'. > Error in ==> discretize5AUGpg at 24 > if (tf == 1) it seems quite obvious: your comparison does not work... put a keyboard; statement in between the above lines and show CSSM the result of disp(tf); us
From: YASMIN M. Yacob on 5 Aug 2010 03:45 Hi, Thanx for the help..it's the problem of referencing..I should have refer to it as: E.labels(m) == E.labels(m+1) > > Hi, > > Need help to compare elements in cell array; used isequal and several other ways but misleading. Cell array is a 20x2 dataset with 3 classes. Wants to compare if the class is the same then proceed to next position ( i.e m act as index) until find changing class else span/skip 6 places. 2nd column is the class. > > Thanks. > > tf = (E(m,2)== E(m+1,2)); %tf=isequal(E(m,2),E(m+1,2)); > > if (tf == 1) > > ??? The following error occurred converting from dataset to logical: > > Undefined function or method 'logical' for input arguments of type 'dataset'. > > Error in ==> discretize5AUGpg at 24 > > if (tf == 1) > > it seems quite obvious: your comparison does not work... > put a > keyboard; > statement in between the above lines and show CSSM the result of > disp(tf); > > us
|
Pages: 1 Prev: How Convert TXT data format to MAT data format Next: LSQR |