Hi everybody,
I have a matrix which is A = [1; 2; 5; 8; 9; 10; 11; 12] and a matrix which contains for pairs of the previous matrix B = [ 1 2; 5 8; 8 9; 9 10 ; 10 11; 11 12 ] I want to complete A but without loosing the pairs in the second matrix. For instance A = [1; 2; 3; 4; 5; 6; 7; 8] B = [ 1 2; 3 4; 4 5; 5 6 ; 6 7; 7 8 ]. How is ti possible to implement this? Thank you in advance

7 comentarios

Adam
Adam el 6 de Jun. de 2018
What do you mean by 'complete A'? Please give a full example of expected results. I don't understand how your second definition of A links in any way to the first or what you want the output to be.
DIMITRA GIANNOPOULOU
DIMITRA GIANNOPOULOU el 6 de Jun. de 2018
Editada: DIMITRA GIANNOPOULOU el 6 de Jun. de 2018
I am sorry. The first matrix is A= [1; 2; 3; 4; 5; 6; 7; 8] and the second matrix contains pairs from the elements of matrix A B = [ 1 2; 5 8; 7 8]. What I want to do is the floating elements of B to be excluded from the matrix A. However I want again the elements of matrix A to be in a row A = [1;2;5;7;8] -> A = [1 ;2 ;3 ;4; 5] without loosing the pairs of matrix B = [1 2;3 5; 4 5].
Jan
Jan el 6 de Jun. de 2018
What are "floating elements"? I see 3 different definitions of the matrix A, two for matrix B and one for "A B", whatever this means. I cannot follow your explanations yet.
Please post the input data, us unique names for the variables, explain the procedure without freshly invented terms like "complete" or "floating", and post the wanted output.
DIMITRA GIANNOPOULOU
DIMITRA GIANNOPOULOU el 6 de Jun. de 2018
I am starting the problem again: Input matrix A= [1; 2; 3; 4; 5; 6; 7; 8] and B = [ 1 2; 5 8; 7 8] (B matrix has pairs of the elements of matrix A). A matrix includes elements that there are not in the matrix B (3 4 6). First, I want to exclude these elements from the matrix A.
After the exclusion I will have a matrix C = [1;2;5;7;8] which I want to sort it such that C = [1;2;3;4;5]. The main problem is that after the sort of C I don't want to loose the pairs of matrix B. So the output matrix B I want to be B = [1 2;3 5; 4 5].
I hope you understand my problem now.I am sorry for the confusion.
Stephen23
Stephen23 el 6 de Jun. de 2018
Editada: Stephen23 el 6 de Jun. de 2018
"After the exclusion I will have a matrix C = [1;2;5;7;8] which I want to sort it such that C = [1;2;3;4;5]."
This is not the definition of SORT in MATLAB or any other programming language, because you are changing the elements themselves, not just their order (which is how sorting is defined). If you want us to understand then you will have to explain the operation that converts [1;2;5;7;8] into [1;2;3;4;5]. Are those the sort indices ?
DIMITRA GIANNOPOULOU
DIMITRA GIANNOPOULOU el 6 de Jun. de 2018
Yes, I want to be in a row the elements. I said sort because I tried the [C,I] = sort(C) and I is actually what I want to contains the matrix C. I am sorry again for the misunderstanding but I am new in the programming.
Stephen23
Stephen23 el 6 de Jun. de 2018
Editada: Stephen23 el 6 de Jun. de 2018
"I don't want to loose the pairs of matrix B"
What defines a "pair": two specific values? Their difference? Not the values but just their positions in the matrix? The relative magnitude?

Iniciar sesión para comentar.

 Respuesta aceptada

Stephen23
Stephen23 el 6 de Jun. de 2018
Editada: Stephen23 el 6 de Jun. de 2018

0 votos

>> A = [1;2;3;4;5;6;7;8];
>> B = [1,2;5,8;7,8];
>> C = A(ismember(A,B));
>> [~,I] = sort(C);
>> [~,X] = ismember(B,C);
>> I(X)
ans =
1 2
3 5
4 5

2 comentarios

DIMITRA GIANNOPOULOU
DIMITRA GIANNOPOULOU el 6 de Jun. de 2018
Thank you very much. It works. I really appreciate your willing to help me. Sorry for any inconvenience.
Stephen23
Stephen23 el 6 de Jun. de 2018
Editada: Stephen23 el 6 de Jun. de 2018
@DIMITRA GIANNOPOULOU: I hope that it helps.
There is no need to apologize! We volunteers come here to help, and sometimes asking for more information or clarifications is part of that. We don't expect people asking to know everything (we certainly don't), so it is perfectly okay to discuss what is required to help resolve the question.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 6 de Jun. de 2018

Editada:

el 6 de Jun. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by