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