How to extract matrix values of a different column that correspond to a value in another column?

1 次查看(过去 30 天)
In the matrix uxcLYS generated, I want to extract only the x,y,z column values that corresponds to 'CB','CG','CD','CE' in the atom name column. How to do it?
uxc = getpdb('1UXC');
No_of_residues = uxc.Sequence.NumOfResidues
No_of_residues = 65
isLYS = ({uxc.Model.Atom.resName} == "LYS");
uxcLYS = uxc.Model.Atom(isLYS)
uxcLYS = 1×110 struct array with fields:
AtomSerNo AtomName altLoc resName chainID resSeq iCode X Y Z occupancy tempFactor segID element charge AtomNameStruct

采纳的回答

Venkat Siddarth
Venkat Siddarth 2023-3-6
Hi @Masha,
I understand that you are trying to extract specifc columns corresponding to few atom names in the above structure.This can be achieved as follows
%Given Code
uxc = getpdb('1UXC');
No_of_residues = uxc.Sequence.NumOfResidues
No_of_residues = 65
isLYS = ({uxc.Model.Atom.resName} == "LYS");
uxcLYS = uxc.Model.Atom(isLYS)
uxcLYS = 1×110 struct array with fields:
AtomSerNo AtomName altLoc resName chainID resSeq iCode X Y Z occupancy tempFactor segID element charge AtomNameStruct
Since uxc is a structure element,for easy access we can convert this to table as follows:
%Structure to Table
req=struct2table(uxc.Model.Atom)
req = 808×16 table
AtomSerNo AtomName altLoc resName chainID resSeq iCode X Y Z occupancy tempFactor segID element charge AtomNameStruct _________ ________ __________ _______ _______ ______ __________ ______ ______ ______ _________ __________ ________ _______ ______ ______________ 1 {'N' } {0×0 char} {'MET'} {'A'} 1 {0×0 char} -7.262 10.686 -0.473 1 2.83 {' '} {'N'} {' '} 1×1 struct 2 {'CA' } {0×0 char} {'MET'} {'A'} 1 {0×0 char} -6.548 9.453 -0.028 1 2.26 {' '} {'C'} {' '} 1×1 struct 3 {'C' } {0×0 char} {'MET'} {'A'} 1 {0×0 char} -6.298 8.511 -1.22 1 2.42 {' '} {'C'} {' '} 1×1 struct 4 {'O' } {0×0 char} {'MET'} {'A'} 1 {0×0 char} -6.779 7.395 -1.261 1 2.69 {' '} {'O'} {' '} 1×1 struct 5 {'CB' } {0×0 char} {'MET'} {'A'} 1 {0×0 char} -7.347 8.762 1.091 1 2.33 {' '} {'C'} {' '} 1×1 struct 6 {'CG' } {0×0 char} {'MET'} {'A'} 1 {0×0 char} -6.383 8.091 2.075 1 2.33 {' '} {'C'} {' '} 1×1 struct 7 {'SD' } {0×0 char} {'MET'} {'A'} 1 {0×0 char} -5.381 9.359 2.895 1 2.65 {' '} {'S'} {' '} 1×1 struct 8 {'CE' } {0×0 char} {'MET'} {'A'} 1 {0×0 char} -3.746 8.634 2.608 1 2.5 {' '} {'C'} {' '} 1×1 struct 9 {'H1' } {0×0 char} {'MET'} {'A'} 1 {0×0 char} -8.171 10.434 -0.913 1 0 {' '} {'H'} {' '} 1×1 struct 10 {'H2' } {0×0 char} {'MET'} {'A'} 1 {0×0 char} -7.432 11.306 0.344 1 0 {' '} {'H'} {' '} 1×1 struct 11 {'H3' } {0×0 char} {'MET'} {'A'} 1 {0×0 char} -6.673 11.197 -1.162 1 0 {' '} {'H'} {' '} 1×1 struct 12 {'HA' } {0×0 char} {'MET'} {'A'} 1 {0×0 char} -5.586 9.751 0.363 1 0 {' '} {'H'} {' '} 1×1 struct 13 {'HB2'} {0×0 char} {'MET'} {'A'} 1 {0×0 char} -7.941 9.495 1.616 1 0 {' '} {'H'} {' '} 1×1 struct 14 {'HB3'} {0×0 char} {'MET'} {'A'} 1 {0×0 char} -7.997 8.012 0.665 1 0 {' '} {'H'} {' '} 1×1 struct 15 {'HG2'} {0×0 char} {'MET'} {'A'} 1 {0×0 char} -6.951 7.545 2.815 1 0 {' '} {'H'} {' '} 1×1 struct 16 {'HG3'} {0×0 char} {'MET'} {'A'} 1 {0×0 char} -5.74 7.407 1.542 1 0 {' '} {'H'} {' '} 1×1 struct
After this we will apply the required constraints;
%converting the column AtomName to string array;
atomName=string(req.AtomName);
%Applying the constraints
ans=req(ismember(atomName,[ "CB","CG","CD","CE"]),["AtomName" "X" "Y" "Z"])
ans = 97×4 table
AtomName X Y Z ________ ______ ______ ______ {'CB'} -7.347 8.762 1.091 {'CG'} -6.383 8.091 2.075 {'CE'} -3.746 8.634 2.608 {'CB'} -4.843 9.06 -4.571 {'CG'} -6.097 9.739 -5.137 {'CD'} -5.812 11.22 -5.419 {'CE'} -6.311 11.618 -6.815 {'CB'} -2.636 4.331 -5.025 {'CG'} -2.609 2.871 -4.565 {'CB'} 0.29 8.746 -5.728 {'CG'} 1.741 8.974 -6.172 {'CB'} -1.262 10.625 -1.019 {'CG'} -2.558 9.887 -0.698 {'CD'} -3.654 10.922 -0.415 {'CB'} -1.304 5.303 0.301 {'CB'} 3.205 5.265 -2.502
I hope this resolves your query.
Thanks,
Venkat Siddarth V

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by