# Grouping multivariant data for Andrewsplot

1 Ansicht (letzte 30 Tage)
xenon99942 am 2 Okt. 2017
Kommentiert: David J. Mack am 4 Okt. 2017
Hi all!
i want to use the andresplot function with grouping specification:
andrewsplot(dspk,'Standardize','on', 'group' ...
Where dspk is a 2500x6 double array. In the documentation it is said that group can consists of either numerical or e.g. a char vector. I want every column of dspk as a own category. so in fact at the end it should be 6 categories, so i created a char vector with 6 names for that categories. But matlab wants "The 'group' parameter value must have one row for each row of X." I tried to transpose the array, but then the plot doesnt make any sense. So transposing is no possibility. Can you help me with this? thanks!
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

David J. Mack am 3 Okt. 2017
Bearbeitet: David J. Mack am 3 Okt. 2017
Hey!
So andrewsplot states that "The rows of X correspond to observations, the columns to variables". It seems that you have instead used the columns to present the groups of observations (e.g. nObs x nGroups instead of nObs x nVars).
Assuming x is indeed nObs=2500 x nGroups=6, the following code will group your data correctly:
andrewsplot(reshape(x,[],1),'Standardize','on','Group',repelem(1:size(x,2),size(x,1));
Since you have only one variable with 2500 observations per six groups,
reshape(x,[],1)
Creates the required nObs=2500*6 x nVars=1 array.
repelem(1:size(x,2),size(x,1))
Creates a nObs=2500*6 x 1 group array with the group members [1...1 2...2 3...3 4...4 5...5 6...6]' etc. (each group block repeated 2500 times). You might replace that with your grouping assignment, e.g.:
repelem(groupNames,size(x,1));
Greetings, David
##### 4 Kommentare3 ältere Kommentare anzeigen3 ältere Kommentare ausblenden
David J. Mack am 4 Okt. 2017
Hey xenon! My bad! I forgot to add that repelem is relatively new addition in Matlab R2015a. In older versions and as a more readable (and slightly faster) alternative to kron use repmat:
g = reshape(repmat(groupNames,size(x,1),1),[],1);
where groupNames is a row vector and x is defined as above. The reshape creates the column vector as in the example above. An additional advantage of repmat is, that you can repeat arbitrary arrays (e.g. also cellstrings with the group labels).
Greetings, David

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!