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

4 Ansichten (letzte 30 Tage)
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 Kommentare
Sim
Sim am 22 Okt. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Matt Fig
Matt Fig am 22 Okt. 2012
Bearbeitet: Matt Fig am 22 Okt. 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.
  1 Kommentar
Sim
Sim am 23 Okt. 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by