How can I assign a number to another number and then create sequences in which I can swap them at will?

1 visualización (últimos 30 días)
Hi guys!
I have a sequence of numbers which I want to assign to another sequence of numbers:
numbers=1:40;
numbers_b=[11:14, 21:24, 31:34, 41:44, 51:54, 61:64, 71:74, 81:84, 91:94, 101:104];
assigned=[numbers; numbers_b]'
assigned =
1 11
2 12
3 13
4 14
5 21
6 22
7 23
8 24
9 31
10 32
11 33
12 34
13 41
14 42
15 43
16 44
17 51
18 52
19 53
20 54
21 61
22 62
23 63
24 64
25 71
26 72
27 73
28 74
29 81
30 82
31 83
32 84
33 91
34 92
35 93
36 94
37 101
38 102
39 103
40 104
Now I want these assignments to be fixed. I have a certain sequence of numbers_b (second column) and I'd like to have a column with the corresponding numbers of numbers (first column).
Example: My sequence starts with 82 11 23 53 82 .....
That would mean I get 30 1 7 19 30 .....
Furthermore, my sequence contains 160 numbers of numbers_b.
Does anybody know how that could be done?
Thanks in advance!
R

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 26 de Sept. de 2020
Editada: Ameer Hamza el 26 de Sept. de 2020
Check this code
numbers=1:40;
numbers_b=[11:14, 21:24, 31:34, 41:44, 51:54, 61:64, 71:74, 81:84, 91:94, 101:104];
assigned=[numbers; numbers_b]';
x = [82 11 63 53 82]; % I guess 3rd number is supposed to be 63 in your question
[~, idx] = ismember(x, assigned(:,2));
y = assigned(idx, 1);
  3 comentarios
Rupert Steinmeier
Rupert Steinmeier el 26 de Sept. de 2020
The third number (23) is supposed to be 23 but the assigned number should be 7, not 63!
Very attentive! :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by