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

1 次查看(过去 30 天)
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 个评论
Sim
Sim 2012-10-22
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.

请先登录,再进行评论。

回答(1 个)

Matt Fig
Matt Fig 2012-10-22
编辑:Matt Fig 2012-10-22
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.
  1 个评论
Sim
Sim 2012-10-23
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by