Hey guys,
I'm new to MATLAB so this might seem silly, but how could I align data-rows by value. So let's say I have a dataset A with N number of rows and one column (column#1), and I have a dataset B with N number of rows and two columns, denoted as column #2, and column #3. Column #1 of dataset A is used as an aligin-template with values ranging from 34 to 700 (in steps of 0.1). Now what I would like to do is pairing the data of column#2 with column #3 so that if column #2 gets aligned with column#1, column#3 will still maintain its position with respect to column#2.
I hope that I'm not confusing you guys, but basically what I want to do is align data by value without losing correlation between two columns
[edit]
maybe this example will clarify what I mean with aligning paired data. So I want to align column #2 with column#1, while column #2 stays paired with column #3. And maybe as an extra fill in 0 if there is no data, but I think I can figure that one out.
align.png
many thanks!

댓글 수: 2

madhan ravi
madhan ravi 2018년 11월 14일
give a shor example with a matrix to understand
Matt J
Matt J 2022년 5월 16일
Rocio Navarro's comment moved here:
Hi, regarding this question, I would have a similar one if you can help me with it. So I also want to align two datasets but in my case values are not totally similar, so I would like to know if there is a script that allows me to align datasets but adding some relative deviation. For example, I want to align values of 13.0 with values ranging from 12.5 to 13.5 (13.0+-0.5). Is this possible?
Thank you very much in advance

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

 채택된 답변

Matt J
Matt J 2018년 11월 15일
편집: Matt J 2018년 11월 15일

2 개 추천

If you have A and B in table form, it's a one-line solution:
%% Build fake data
A=linspace(31,32,11).';
B=A([2,5,7,9]); B=[B,rand(size(B))];
A=array2table(A);
B=array2table(B);
%% Solution
>> result =outerjoin(A,B,'LeftKeys','A','RightKeys','B1')
result =
11×3 table
A B1 B2
____ ____ _______
31 NaN NaN
31.1 31.1 0.63236
31.2 NaN NaN
31.3 NaN NaN
31.4 31.4 0.09754
31.5 NaN NaN
31.6 31.6 0.2785
31.7 NaN NaN
31.8 31.8 0.54688
31.9 NaN NaN
32 NaN NaN

댓글 수: 2

Felix Flores James
Felix Flores James 2018년 11월 15일
Thank you so much!
Khanyisile
Khanyisile 2023년 3월 23일
Thank you so much

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2018년 11월 14일

댓글:

2023년 3월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by