Merge two cells of different size but have one rows in common

Hello Guys,
I have two Matlab cells that I have one row in common. I have to merge to Add to the first the uncommon rows of the second one.
commonValue=intersect(r_ptf{12,:},r_ptf3{12,:});
Could someone help me out

4 件のコメント

Dyuman Joshi
Dyuman Joshi 2023 年 1 月 25 日
It's difficult to say without the data. Attach it using the paperclip icon or give a sample data, and mention the desired output.
Yao Lionel
Yao Lionel 2023 年 1 月 25 日
I have two cells data one with 1318*1989 cells and the seconde with 1318*2962. the common element is situate in rows 12 and I want to add the common element to previous want so that the final size of the first one table would be 1318*2962.
Yao Lionel
Yao Lionel 2023 年 1 月 25 日
@Dyuman Joshi is it a good answer for you to help me out
dpb
dpb 2023 年 1 月 25 日
When it comes to cell arrays, it's pretty-much impossible to write generic code w/o knowing the content since it could be anything.
As @Dyuman Joshi requested, for somebody to be able to help, we'll need to see a small sample case that illustrates what the content of the two cell arrays is...it doesn't need (and shouldn't be) huge; just make up a test case that illustrates wht your situation is...only 10 or so rows and columns would be more than enough; but it needs to be representative of the real thing.

サインインしてコメントする。

回答 (1 件)

Sarthak
Sarthak 2023 年 3 月 6 日

0 投票

Hi,
Here are the steps and the code you could refer:
% Find the common value
commonValue = intersect(r_ptf{12,:}, r_ptf3{12,:});
% Find the indices of the rows that have the common value in both cells
idx1 = find(ismember(r_ptf{12,:}, commonValue));
idx2 = find(ismember(r_ptf3{12,:}, commonValue));
% Remove the rows with the common value from the second cell
r_ptf3(idx2,:) = [];
% Merge the two cells by adding the uncommon rows of the second cell to the first cell
r_ptf = [r_ptf; r_ptf3];
Refer to the following documentation for ismember:

カテゴリ

ヘルプ センター および File Exchange で MATLAB についてさらに検索

質問済み:

2023 年 1 月 25 日

回答済み:

2023 年 3 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by