Effacer les filtres
Effacer les filtres

gscatter grouping variable

14 vues (au cours des 30 derniers jours)
Avishek Dutta
Avishek Dutta le 4 Juin 2012
Hi all,
I need some help with the input parameters of gscatter. I am a beginner so please overlook if my questions are silly.
I am trying to do a supervised classification of Inertial data. My user selects two points (start and end) from a plot, where all the training classes are shown together either the accleration or gyro etc. I save this region and call classify() on this sample. The function gives me a vector denoting to which group of my training this sample belongs. Now I wish to plot this information.
I am using gscatter(T,C,group). T is 1 to the row count of C. C is the result of the classify() i.e it is of the size of the sample prevously chosen and group is vector where the training groups are indicated. For example rows 1-130 has value 1, 131-162 has value 2 and so on. Row count of group is same as that of all training classes summed together.
I get an error, *??? Error using ==> gscatter at 84 There must be one value of G for each row of X. *
Please help.
Avishek
  3 commentaires
Avishek Dutta
Avishek Dutta le 5 Juin 2012
size(T) = size(C) = 294, 1 for example depends on the points the user chooses. size(group) is 494, 1.
Oleg Komarov
Oleg Komarov le 5 Juin 2012
It would be simpler if you posted a code snippet that reproduced the error.

Connectez-vous pour commenter.

Réponse acceptée

Tom Lane
Tom Lane le 5 Juin 2012
The idea is that the jth point on the plot is x=T(j) vs y=C(j) with the symbol chosen according to the group value group(j). They should all have the same number of points. If you are subsetting your data to get T and C (I can't tell from your description if that is the case), perhaps you need to subset the group variable the same way.

Plus de réponses (1)

Avishek Dutta
Avishek Dutta le 5 Juin 2012
Yes, Thanks Tom, I realise that all three of them must have the same row count. Anyways, I wiil try to explain a bit more clearly,
u = pointx2-pointx1; *% points given by user*
training = [combData(:,7) combData(:,8) combData(:,9) combData(:,10) combData(:,11) combData(:,12) combData(:,13) combData(:,14) combData(:,15) combData(:,16) combData(:,18) combData(:,24) combData(:,25) combData(:,26) ];
  • % training data is combData is a matrix of 494 by 28. I need only the mentioned cols for my classification
% combData wass made by combining raw data files of run, walk, sit etc scenarios (total 7) together*
[rows,~]=size(combData);
% groupSize has the rowcount of each scenario e.g. groupSize = [numofRowsofRun numofRowsofWalk etc...];
for i = 1:rows
if i <= groupSize(1)
group(i,1) = 1;
elseif i > groupSize(1) && i <= sum(groupSize(1:2))
group(i,1) = 2;
elseif i > sum(groupSize(1:2)) && i <= sum(groupSize(1:3))
group(i,1) = 3;
elseif i > sum(groupSize(1:3)) && i <= sum(groupSize(1:4))
group(i,1) = 4;
elseif i > sum(groupSize(1:4)) && i <= sum(groupSize(1:5))
group(i,1) = 5;
elseif i > sum(groupSize(1:5)) && i <= sum(groupSize(1:6))
group(i,1) = 6;
elseif i > sum(groupSize(1:6))
group(i,1) = 7;
end
end
%hence group has for eg [1 1 1 1 2 2 2 2 3 3 3.....7 ] for 494 rows
[~,cols] = size(training);
sample = zeros(u+1,cols);
for i = 1 : cols
sample(:,i) = training(pointx1:pointx2,i);
end
% Classify the FullData:
[C,err,P,logp,coeff] = classify(sample,training,group,'diagquadratic');
I want to plot this C vector which has for eg [2 2 2 3 4 etc..]. My idea is to have 1-7 on y-axis and plot the values inside C w.r.t the range pointx1-pointx2.
I did this,
T = pointx1:pointx2;
gscatter(T',C,group,'rgb','*');
I feel that gscatter may not be useful here, also there is no getting past the fact that all three vectors have to be of same size. Is there something else I can do to fulfill my requirement?
Thanks for all your help.
p.s. Oleg hope this code helps
  1 commentaire
Tom Lane
Tom Lane le 5 Juin 2012
If training and group have the same size, and you take the pointx1:pointx2 subset of training to get sample, and you compute C for sample, then I would think you want to supply group(pointx1:pointx2) when you run gscatter.

Connectez-vous pour commenter.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by