Vertically concatenate a 2 column comma separated list

2 ビュー (過去 30 日間)
RuiQi
RuiQi 2017 年 1 月 17 日
コメント済み: Carlos Soto 2018 年 7 月 26 日
I have a structure of size 100 extracted from regionprops called stat. Id like to extract the column of data that stores the centroids of each component. Since they are in a list, I tried
centroids = [stat(:).Centroid]';
but it gives me an array of size 200 meaning it doesnt concatenate properly. Then I tried
x = [stat(:).Centroid(1)];
y = [stat(:).Centroid(2)];
but I get an error "Scalar index required for this type of multi-level indexing". Id like the result to be an array of 100 rows and 2 columns. Can someone suggest what I can do ? This is so difficult.
  1 件のコメント
Carlos Soto
Carlos Soto 2018 年 7 月 26 日
vertcat(stat.Centroid) does it

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

採用された回答

Guillaume
Guillaume 2017 年 1 月 17 日
[a, b] is the same as horzcat, [a; b] is the same as vertcat, so to obtain the result you want:
centroids = vertcat(stat.Centroid);
  1 件のコメント
RuiQi
RuiQi 2017 年 1 月 17 日
wow i didnt know such a function existed. I guess thats how I will handle comma separated lists in the future thanks !

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

その他の回答 (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