How to transform a random vector into an ordered vector without losing the correlation in Matlab

0

Hello, I am trying to run a power flow program (electrical engineering). The routine works perfectly if the bar number vector is of the type:

A=[1;2;3;4;5;6;7;8]

The problem is that eventually I come across vectors of the type:

B=[1;2;7;8;9;15;16;17]

One solution I was thinking was to map the 'B' vector (which occurs) to the 'A' vector (created during the routine). The problem is that: since the program rotates and converges, I need to have the results as a function of vector 'A' and not the auxiliary vector 'B', so this correlation can not be lost.

My best idea is to create an array where column 1 is vector A and column 2 is vector B. Is there any better way to do this?

    
asked by anonymous 06.09.2017 / 18:56

1 answer

0

This may be a function fault that is using the A vector. A better option is to find out the source of the problem, but the solution that is possible based on your question is below.

Create a vector with all possible members and then select your answer with the original vector.

Note: Be aware that the vector you have placed is sorted and does not display repeated values. If you have values like this, you need a little code adaptation, to call in order and with repeated values ( ismember ignore repeated values).

%vetor original
a=[3;7;10];
%vetor linearmente espacado
b=1:1:(max(a)+1);
%ajeito para coluna
b=b'; %Aqui o vetor está pronto pra usar. Use como entrada a seus cálculos.

% Assumindo a resposta está dada no vetor  ""r"", que pela sua explicacão 
% tem o mesmo tamanho do ""b""

r_ajustado=r(ismember(b,a)); %este vetor tem o mesmo tamanho de ""a"", 
%com os respectivos membros de ""a"". 
    
11.09.2017 / 21:14