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

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by