Vertically concatenate a 2 column comma separated list

조회 수: 1 (최근 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.

채택된 답변

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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by