# How to tag output of function which is a vector in a new array/matrix in increasing order?

2 views (last 30 days)
Sim on 22 Oct 2012
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.
##### 2 CommentsShowHide 1 older comment
Sim on 22 Oct 2012
Say I already have a pre-defined list
list = [1
2
3
4
5
6
7
.
.
.
.
So whenever I get an output from 'a' I would like to tag them in this list. For example,
a = [4 6]
list = [ 1
2
3
4 1
5
6 1
7]
next time if
a= [ 1 2]
List should be updated to
list = [ 1 2
2 2
3
4 1
5
6 1
7 ]
If there is nothin the values could be Nan as I will predefine List with NaN. Does this make sense? I just have an idea but I do not know how to go forward with it.

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.
Sim on 23 Oct 2012
I am getting an error for the '+' command. I am trying to populate a list/matrix with the output of the function. The output of the function are the indices of the matrix. So suppose if the output of funtion is [6 10] I want it to go back to the matrix and just append 1 1 for the row of 6 and 10.