to retrieve data from a n*n matrix

9 vues (au cours des 30 derniers jours)
bilhan
bilhan le 8 Avr 2012
hi i have x=[2 4 2 6 1;4 3 6 3 3; 2 5 6 4 1;3 4 5 2 2;3 5 2 6 3]
the first four coloumns represents bins 1 to 6 and the 5th column represents the class
a) i want to know the no of elements present in each bin based on the data given in first four columns as a row vector of size 1*6 the answer must be[0 5 4 4 3 4]
b)i want to get 3 different matrices based on the class that is the fifth column
answer: class1=[2 4 2 6 1;2 5 6 4 1] class2=[3 4 5 2 2] class3=[4 3 6 3 3;3 5 2 6 3]
Thanks in advance

Réponse acceptée

Oleg Komarov
Oleg Komarov le 8 Avr 2012
a)
data = x(:,1:end-1);
histc(data(:),1:max(data(:))).'
b) Why would you want to separate it when yuo can index it?
class1 = x(x(:,end) == 1,:);
class2 = x(x(:,end) == 2,:);
class3 = x(x(:,end) == 3,:);
  1 commentaire
bilhan
bilhan le 8 Avr 2012
Thank you Mr.Komarov

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Spline Postprocessing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by