Instead of dynamically creating a bunch of matrices, I would create a cell array with each matrix in a separate cell. Here's one way to do this, using the functions SORT and MAT2CELL : cluster,sortIndex = sort(cluster); %# Sort cluster and get sorting index data = data(sortIndex,:); %# Apply the same sorting to data clusterCounts = diff(0 find(diff(cluster)) numel(cluster)); %# Find size of %# each cluster cellArray = mat2cell(data,clusterCounts,2); %# Break up data into matrices, %# each in a separate cell.
Instead of dynamically creating a bunch of matrices, I would create a cell array with each matrix in a separate cell. Here's one way to do this, using the functions SORT and MAT2CELL: cluster,sortIndex = sort(cluster); %# Sort cluster and get sorting index data = data(sortIndex,:); %# Apply the same sorting to data clusterCounts = diff(0 find(diff(cluster)) numel(cluster)); %# Find size of %# each cluster cellArray = mat2cell(data,clusterCounts,2); %# Break up data into matrices, %# each in a separate cell.
You can use ARRAYFUN to distribute the coordinates among different cell arrays. %# create sample data clusterIdx = 2,0,3,1,1,1,3,2; coordinates = rand(8,2); %# first you get a list of unique cluster indices clusterIdxUnique = unique(clusterIdx); %# then you use arrayfun to distribute the coordinates clusterCell = arrayfun(@(x)coordinates(clusterIdx==x,:),clusterIdxUnique,'UniformOutput',false); The first element of clusterCell contains the coordinates corresponding to the first entry in clusterIdxUnique, etc.
I guess this is the solution: data(cluster == i, :) where I is the index of the cluster. Your index matrix is converted to a boolean matrix and then used to index the rows and each selected row is completely added to the resulting matrix. If this is not what you're looking for, please specify your needs more clearly.
Thanks, I guess this is the solution to extract them from the 2-D matrix based on cluster matrix. The problem is the number of clusters, in other words, the range of numbers in the cluster array is not known. And in each run they will be different.
Sometime 5,6,7,10,..... I have to find a way so I can dynamically alot matrixes to extract data to them from DATA matrix.... – Hossein May 30 '10 at 13:47 Assuming they get number incrementally and without gaps, call max on your index vector. You can loop over all possibles index values in that way, performing your desired operations on each cluster. – Pieter May 30 '10 at 14:15 agree.
But I want to save them in different matrixes how do I define matrixes dynamicaly? – Hossein May 30 '10 at 14:19 Use multi-dimensional arrays. – Pieter May 30 '10 at 14:31.
Thanks everyone, I managed to make it work with this code: noOfClusters = max(cluster); %without noise for i=1:noOfClusters C(i,1) = {numData(cluster==i,:)} end I assume your codes are much faster,cause you don't use for loops.
There are a few problems with your code: 1) If 0 is a value in class, it will be ignored. 2) You should avoid using the word class for a variable name, since it is a built-in function in MATLAB. 3) You don't really have to use the variable h.
You can use the loop variable I instead. – gnovice May 30 '10 at 20:10 Oh, yes thank you, I didn't notice that I will fix it, also I do this because I don't have cluster 0. But again thank you for your comments.
– Hossein May 30 '10 at 20:17.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.