フィルターのクリア

copy matched data with multiply\duplicate

1 回表示 (過去 30 日間)
Amr Hashem
Amr Hashem 2015 年 5 月 15 日
編集済み: Amr Hashem 2015 年 5 月 16 日
i have this two tables querymdr & idx2 :
i want to compare the fisrt two coulmns of them , and the multiple value copy column 6 of it only
i want to have the answer like this:
what i can do? any one has an idea?
  3 件のコメント
Amr Hashem
Amr Hashem 2015 年 5 月 16 日
yes.
i want to delete the duplicated rows. with saving their 6th values
Amr Hashem
Amr Hashem 2015 年 5 月 16 日
how i can do this? any idea...

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

採用された回答

Geoff Hayes
Geoff Hayes 2015 年 5 月 16 日
amr - There are several ways to do this. If we assume that the first column is in ascending order (will this always be true?), then you can iterate over each row and find those that have the same element in the first row. Try the following
numCols = 6;
% initialize the text array
textArray = cell(size(idx2,1),numCols);
atRow = 1;
% iterate over each row of idx2
start = 1;
for k=2:size(idx2,1)
% check to see if the kth row is different from the starting row
if idx2{k,1} ~= idx2{start,1}
% create the new row
textArray(atRow,1:numCols) = idx2(start, 1:numCols);
for r=1:(k - start - 1)
text(atRow, numCols + r) = idx2(start + r, numCols);
end
start = k;
atRow = atRow + 1;
end
end
% repeat for the final row of idx2
textArray(atRow,1:numCols) = idx2(start, 1:numCols);
for r=1:(k - start)
textArray(atRow, numCols + r) = idx2(start + r, numCols);
end
Note that text may have several blank rows that you can remove as
textArray(atRow+1:end,:) = [];
Note that text is the name of a built-in MATLAB function so in the above example I renamed it to textArray. (Always try to avoid creating variable with names of MATLAB functions to avoid future headaches when trying to debug the code.)
  1 件のコメント
Amr Hashem
Amr Hashem 2015 年 5 月 16 日
編集済み: Amr Hashem 2015 年 5 月 16 日
thank you very much ( & as we say in Arabic : شكرا )
it works
that's kind & great from you.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by