Problem with using reshape

조회 수: 3 (최근 30일)
Ivan Lozancic
Ivan Lozancic 2019년 6월 1일
편집: Ivan Lozancic 2019년 6월 1일
I have a problem using reshape function. I want to extract my angles from data matrix into new matrix, dividing them into 2 colums (new column for each angle).
This is my data matrix:
data =
-13 -1515,21041600000
-13 -1472,44425940753
-13 -1073,29699036918
-13 -1038,18702400000
-13 -1037,46604000000
-13 -726,128784972022
-13 -593,565533279872
-13 -487,207584000000
-13 -472,548334667734
-13 -407,240495207668
-13 -405,700448000000
-12 -1515,21041600000
-12 -1472,44425940753
-12 -1073,29699036918
-12 -1038,18702400000
-12 -1037,46604000000
-12 -726,128784972022
-12 -724,533918269230
-12 -593,565533279872
-12 -487,207584000000
-12 -472,548334667734
-12 -407,240495207668
-12 -405,700448000000
This is what I want to get:
angles =
-13 -12
-13 -12
-13 -12
-13 -12
-13 -12
-13 -12
-13 -12
-13 -12
-13 -12
-13 -12
-13 -12
I tried using reshape function for it, something like this:
angles=reshape(data(:,1),[],2)';
But since each of my angles repeat 11 times, I have 23 rows in my data matrix so I get error like this:
Error using reshape
Product of known dimensions, 2, not divisible into total number of elements, 23.
EDIT: I found the problem in the rest of my code which caused my first angle to have 1 less entry. Sorry for wasting your time.

채택된 답변

Walter Roberson
Walter Roberson 2019년 6월 1일
No that cannot be done by reshape alone. You have 11 entries with 13 but you have 12 entries with 12. Are you willing to discard the last entry to make the same number of each?
  댓글 수: 1
Ivan Lozancic
Ivan Lozancic 2019년 6월 1일
Ah, I swear I'm actually blind. I found the problem in other part of my code which made first angle to have only 11 entries while the rest had 12. I guess I should've checked the length of other angles first, lesson learned.
Thanks for the help anyways.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by