フィルターのクリア

Extract cell value based on row contents

2 ビュー (過去 30 日間)
Karuna Skipper
Karuna Skipper 2023 年 2 月 13 日
コメント済み: Karuna Skipper 2023 年 2 月 13 日
I have a table with 4 columns (id1, id2, HB, and FENE) and many thousands of rows. From this I would like to create a new table of HB data, extracted if the id1 and id2 contain particular values. For instance:
id1 id2 HB FENE
1 28 0.718 281
1 31 0.572 256
1 07 0.182 413
2 28 0.271 361
2 31 0.725 249
2 07 0.012 992
1 28 0.381 438
2 31 0.991 913
if I am interested in the id combinations of [1,28] and [2,31], I want to produce the table:
1+28 2+31
0.718 0.725
0.381 0.991
In the dataset there will always be the same number of id combinations (i.e. if there are five rows containing [1,28], there are also five rows of [2,31]).
My current process is:
id1 = [1 2 3 4 5]
id2 = [28 31 34 37 40]
dataFile = file.txt
dataOutput = zeros(1,5)
for k = 1:5
head1 = strand1(k)+"+"+strand2(k)
if dataFile{:,1} == strand1(k)
if dataFile{:,2} == strand2(k) %both conditions must be true to proceed
?? extract data from this row, in col 3, and append to dataOutput in col k, new row
end
end
%loops in k=1 until all instances are found
%do i have to define how many times to loop for k=1?
end
outputTable = array2table(dataOutput)
outputTable.Properties.VariableNames(1:5) = {'head1','head2','head3','head4','head5'}
Thank you very much for any pointers or advice.

採用された回答

Askic V
Askic V 2023 年 2 月 13 日
編集済み: Askic V 2023 年 2 月 13 日
Here is one example that should give you an idea how to proceed:
A = [1 28 0.718 281
1 31 0.572 256
1 07 0.182 413
2 28 0.271 361
2 31 0.725 249
2 07 0.012 992
1 28 0.381 438
2 31 0.991 913];
ind = find((A(:,1) == 1) & (A(:,2) == 28))
ind = 2×1
1 7
A_1_28 = A(ind,3)
A_1_28 = 2×1
0.7180 0.3810
  1 件のコメント
Karuna Skipper
Karuna Skipper 2023 年 2 月 13 日
Thanks very much!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by