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

Asked

Viewed 69 times

0

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

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

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

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

One solution I was thinking of was to correlate the vector 'B' (which occurs) with the vector 'A' (created during the routine). The problem is that: once the program runs and converges, I need to have the results as a function of vector 'A' and not auxiliary vector 'B', so this correlation cannot 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?

  • What do you call "random vector"? For me B is in the same ordination as A: nondecreasing

  • I necessarily need the vector to start at 1 and end at N (where N is the last bar). Hence the creation of an auxiliary vector.

  • You need a vector of consecutive numbers started at 1?

  • Exactly! And I can’t lose the correlation with vector A (disordered) in the case.

1 answer

0

This may be a fault in the function that is using the vector A. A better option is to find out the origin 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:Note that the vector you placed is ordered and does not present repeated values. If you have values like this, it is necessary a small adaptation of the code, to call in order and with repeated values( ismember ignores 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"". 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.