How can I compare two cells which consist of the same values, and write the row number of the first to the other file

3 ビュー (過去 30 日間)
I have following two cells, where C is basically created by following code:
--------------------------------------------------------------
Nodes = cell2table(AllCell);
Nodes_Unique = unique(Nodes,'rows');
AllNodes = table2cell(Nodes_Unique);
n = size(AllNodes,1);
N = 0:(n-1);
a = rand(1,10000);
b = N';
B = num2cell(b);
C = [AllNodes,B];
--------------------------------------------------------------
C =
5×4 cell array
{'+0.0000000E+00'} {'+0.0000000E+00'} {'+0.0000000E+00'} {[0]}
{'+0.0000000E+00'} {'+5.0000000E+00'} {'+0.0000000E+00'} {[1]}
{'+2.5000000E+00'} {'+2.5000000E+00'} {'+5.0000000E+00'} {[2]}
{'+5.0000000E+00'} {'+0.0000000E+00'} {'+0.0000000E+00'} {[3]}
{'+5.0000000E+00'} {'+5.0000000E+00'} {'+0.0000000E+00'} {[4]}
--------------------------------------------------------------
AllCell =
12×3 cell array
{'+0.0000000E+00'} {'+5.0000000E+00'} {'+0.0000000E+00'}
{'+0.0000000E+00'} {'+0.0000000E+00'} {'+0.0000000E+00'}
{'+2.5000000E+00'} {'+2.5000000E+00'} {'+5.0000000E+00'}
{'+0.0000000E+00'} {'+5.0000000E+00'} {'+0.0000000E+00'}
{'+5.0000000E+00'} {'+5.0000000E+00'} {'+0.0000000E+00'}
{'+5.0000000E+00'} {'+0.0000000E+00'} {'+0.0000000E+00'}
{'+5.0000000E+00'} {'+0.0000000E+00'} {'+0.0000000E+00'}
{'+0.0000000E+00'} {'+0.0000000E+00'} {'+0.0000000E+00'}
{'+0.0000000E+00'} {'+5.0000000E+00'} {'+0.0000000E+00'}
{'+2.5000000E+00'} {'+2.5000000E+00'} {'+5.0000000E+00'}
{'+5.0000000E+00'} {'+0.0000000E+00'} {'+0.0000000E+00'}
{'+5.0000000E+00'} {'+5.0000000E+00'} {'+0.0000000E+00'}
--------------------------------------------------------------
I would like to compare each row of the 2nd cell (AllCell) with the 1st cell (C) and write the 4th column value of the 1st cell to the 2nd cells 4th column (AllCell) if the rows (or first 3 columns) match. The result should be like this:
{'+0.0000000E+00'} {'+5.0000000E+00'} {'+0.0000000E+00'} {[1]}
{'+0.0000000E+00'} {'+0.0000000E+00'} {'+0.0000000E+00'} {[0]}
{'+2.5000000E+00'} {'+2.5000000E+00'} {'+5.0000000E+00'} {[2]}
{'+0.0000000E+00'} {'+5.0000000E+00'} {'+0.0000000E+00'} {[1]}
etc.
How can I achieve this comparison of those two cells? I could use tables too if cells don't work.

採用された回答

Turlough Hughes
Turlough Hughes 2019 年 11 月 3 日
編集済み: Turlough Hughes 2019 年 11 月 3 日
You actually don't need to run the comparisons. The unique function provides for this directly. So just modify the second line of your code as follows:
[Nodes_Unique,~,idx] = unique(Nodes,'rows');
And you can include the fourth column in AllCell as follows:
idx=idx-1; % seeing as you prefer to start with 0.
idx = num2cell(idx);
AllCell = [AllCell,idx];
  2 件のコメント
Daniel Rohrer
Daniel Rohrer 2019 年 11 月 3 日
Alrighty, that works perfectly well. Thank you very much!
Turlough Hughes
Turlough Hughes 2019 年 11 月 4 日
Great. Can you accept the answer in that case.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeReporting and Database Access についてさらに検索

タグ

タグが未入力です。

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by