Problem with using reshape

4 views (last 30 days)
Ivan Lozancic
Ivan Lozancic on 1 Jun 2019
Edited: Ivan Lozancic on 1 Jun 2019
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.

Accepted Answer

Walter Roberson
Walter Roberson on 1 Jun 2019
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 Comment
Ivan Lozancic
Ivan Lozancic on 1 Jun 2019
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.

Sign in to comment.

More Answers (0)

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!