How to tag output of function which is a vector in a new array/matrix in increasing order?
1 view (last 30 days)
Show older comments
I have an output of a function which is a vector:
a = [ 4 3 8 27 10]
These are all the indices. My function runs for about 100k files. Everytime I get a new set of indices as a. What I intend to do is tag these indices in a separate array/ matrix. So,
a = [4 3 8 27 10]
should be tagged as [1 1 1 1 1] in the new array/ matrix. Then for next set of
a = [ 25 17 89 11]
should be tagged as [ 2 2 2 2 ] and so on.So basically I want them to be in increasing order. Is there a solution to this? Thanks much in advance.
Answers (1)
Matt Fig
on 22 Oct 2012
Edited: Matt Fig
on 22 Oct 2012
A{1} = [ 4 3 8 27 10];
A{2} = [4 3 8 27 10];
% etc...
Then later you can examine them:
A{2}
.
.
.
.
.
EDIT
Wow! What a difference a thorough description (found in the comments above) makes.
list = [(1:10).' zeros(10,1)];
A = [2 3 4 3 4 1 9 8 7] % given vector
I = unique(A);
J = histc(A,I);
list(I,2) = list(I,2) + J.' % Add them to the counts.
Now say we get another A, just do it again:
A = [4 2 3 2 6 7 8 9];
I = unique(A);
J = histc(A,I);
list(I,2) = list(I,2) + J.' % Add them to the counts.
See Also
Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!