Extract cell value based on row contents
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Karuna Skipper
am 13 Feb. 2023
Kommentiert: Karuna Skipper
am 13 Feb. 2023
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.
0 Kommentare
Akzeptierte Antwort
Askic V
am 13 Feb. 2023
Bearbeitet: Askic V
am 13 Feb. 2023
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))
A_1_28 = A(ind,3)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!