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

Adam
Adam 2018년 6월 6일
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 2018년 6월 6일
편집: DIMITRA GIANNOPOULOU 2018년 6월 6일
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 2018년 6월 6일
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 2018년 6월 6일
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 2018년 6월 6일
편집: Stephen23 2018년 6월 6일
"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 2018년 6월 6일
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 2018년 6월 6일
편집: Stephen23 2018년 6월 6일
"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?

댓글을 달려면 로그인하십시오.

 채택된 답변

Stephen23
Stephen23 2018년 6월 6일
편집: Stephen23 2018년 6월 6일

0 개 추천

>> 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

DIMITRA GIANNOPOULOU
DIMITRA GIANNOPOULOU 2018년 6월 6일
Thank you very much. It works. I really appreciate your willing to help me. Sorry for any inconvenience.
Stephen23
Stephen23 2018년 6월 6일
편집: Stephen23 2018년 6월 6일
@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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

질문:

2018년 6월 6일

편집:

2018년 6월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by