フィルターのクリア

How can I get coordinates from a grouping inside of a matrix.

1 回表示 (過去 30 日間)
Jonathan Salazar
Jonathan Salazar 2017 年 7 月 29 日
回答済み: Image Analyst 2017 年 7 月 29 日
I have a matrix with 5 columns: atom number, mol_tag, then the x y and z coordinates. The mol_tag seperate the atoms into globules by sharing a common value, I need a matrix that will give three coordinates from each grouping of mol_tag so that I can calculate the normal vector to each of the mol_tag groupings. thank you!

採用された回答

Walter Roberson
Walter Roberson 2017 年 7 月 29 日
mol_tags = YourMatrix(:,2)
unique_mol_tags = unique( mol_tags );
num_tags = length(unique_mol_tags);
mol_normals = zeros(num_tags, 3);
for K = 1 : num_tags
three_idx = find( mol_tags == unique_mol_tags(K), 3, 'first');
coords = YourMatrix(three_idx, 3:5);
this_normal = ..... something with the coords
mol_normals(K, :) = this_normal;
end
It is possible to code the coordinate finding part without any explicit loop, but I do not think the result would be any clearer, as it involves some advanced accumarray hacks.

その他の回答 (1 件)

Image Analyst
Image Analyst 2017 年 7 月 29 日
If by the "three coordinates from each grouping of mol_tag" you mean the mean x, y, and z over all rows with that mol_tag value, you can use grpstats() if you have the Statistics and Machine Learning Toolbox

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by