From: YASMIN M. Yacob on 3 Aug 2010 00:12 I have error on the sorting part,I have tried cell but does no effect . What I want to do is to sort each column from data (i.e sort by the attribute/field) and the labels/class will follow. Hope can help me. Thanx. e.g from iris dataset; simplified version SL SW PL PW labels 1.2 2.1 3.1 4.1 1 0.9 2.2 3.2 3.9 2 SL labels 0.9 2 1.2 1 SW labels 2.1 1 2.2 2 and so on. load data load labels [nobs,nvars] = size(data); A = dataset(data, labels); for i=1:nvars B = [A(:,i) A.labels]; %OK disp(B(1:nobs,1:nvars)); %OK C= sortrows(B,1); end Sample run and error: 5 by 2 dataset with 2 classes: [3 2] 1.5000 1.0000 1.2000 1.0000 1.6000 2.0000 1.3000 2.0000 1.4000 1.0000 ??? Reference to non-existent field ‘nvars’. Error in ==> getvarindices at 61 if maxIndex > a.nvars Error in ==> dataset.sortrows at 53 vars = getvarindices(a,vars,false); Error in ==> discretize1aug900 at 9 C= sortrows(B,1);
From: Oleg Komarov on 3 Aug 2010 03:20 "YASMIN M. Yacob" <yasmin160273(a)yahoo.com> wrote in message <i384um$8be$1(a)fred.mathworks.com>... > I have error on the sorting part,I have tried cell but > does no effect . What I want to do is to sort each column from data (i.e sort by the attribute/field) and the labels/class will follow. Hope can help me. Thanx. > e.g from iris dataset; simplified version > SL SW PL PW labels > 1.2 2.1 3.1 4.1 1 > 0.9 2.2 3.2 3.9 2 > SL labels > 0.9 2 > 1.2 1 > SW labels > 2.1 1 > 2.2 2 > and so on. > load data > load labels > [nobs,nvars] = size(data); > A = dataset(data, labels); > for i=1:nvars > B = [A(:,i) A.labels]; %OK > disp(B(1:nobs,1:nvars)); %OK > C= sortrows(B,1); > end > Sample run and error: > 5 by 2 dataset with 2 classes: [3 2] > 1.5000 1.0000 > 1.2000 1.0000 > 1.6000 2.0000 > 1.3000 2.0000 > 1.4000 1.0000 > ??? Reference to non-existent field ‘nvars’. > Error in ==> getvarindices at 61 > if maxIndex > a.nvars > Error in ==> dataset.sortrows at 53 > vars = getvarindices(a,vars,false); > Error in ==> discretize1aug900 at 9 > C= sortrows(B,1); Apart from the fact that line: B = [A(:,i) A.labels] should be: B = [A.data(:,i) A.labels] You're not telling the whole story, I don't get any error. Post here the result of "whos data" and "whos labels". Also, do you create C somewhere before? Oleg
|
Pages: 1 Prev: Facealpha change affects everything I plot. Next: Help.. |