设置从 1 到 N 的不同数字

set the different number from 1 to N

我有多个节点A,我想按顺序从1到4更改编号。并在以下代码中将link更改为link_new。你能帮我吗?

A= [23;
    24; 
    27; 
    45];
link= [23 24;
       24 27 ;
       24 45;
       27 45];

结果

A_new = [1;
         2;
         3;
         4]
link_new =[1 2;
           2 3;
           2 4;
           3 4]
A = [23; 24; 27; 45];
link = [23, 24; 24, 27; 24, 45; 27, 45];

A_new = A;
link_new = link;
for idx = 1:numel(A)
  a = A(idx);
  A_new(idx) = idx;
  link_new(link_new == a) = idx;
end