Inconsistent dimensions of arrays

Hi. I am trying to add the Park Transformation matrix to my m file but it won't run. The error message reads:
>> Park_Transformation_matrix
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
Error in Park_Transformation_matrix (line 4)
Park_1 = [cos(theta) cos(theta-(2*pi/3)) cos(theta+(2*pi/3));
My code is simply the matrix itself:
theta=0:0.01:2*pi;
Park_1 = (2/3)*[cos(theta) cos(theta-(2*pi/3)) cos(theta+(2*pi/3));
-sin(theta) -sin(theta-(2*pi/3)) -sin(theta+(2*pi/3));
0.5 0.5 0.5];

 Accepted Answer

Note what the upper-left element of your array is:
theta=0:0.01:2*pi;
cos(theta)
ans = 1×629
1.0000 1.0000 0.9998 0.9996 0.9992 0.9988 0.9982 0.9976 0.9968 0.9960 0.9950 0.9940 0.9928 0.9916 0.9902 0.9888 0.9872 0.9856 0.9838 0.9820 0.9801 0.9780 0.9759 0.9737 0.9713 0.9689 0.9664 0.9638 0.9611 0.9582
So, you are trying to concatenate two rows that have 1,887 elements with one row that has 3 elements.
It looks like you intended to create the matrix as a function of theta. You can do this as follows:
Park_1 = @(theta) ((2/3)*[cos(theta), cos(theta-(2*pi/3)), cos(theta+(2*pi/3)); ...
-sin(theta), -sin(theta-(2*pi/3)), -sin(theta+(2*pi/3)); ...
0.5, 0.5, 0.5 ]);
Park_1(pi)
ans = 3×3
-0.6667 0.3333 0.3333 -0.0000 -0.5774 0.5774 0.3333 0.3333 0.3333
You still cannot call this with a vector theta, though. Depending on how you want to use this in a next step, you may need to code it differently.

More Answers (1)

Your theta is on the order of 625 elements long. What size are you expecting sin(theta) to be? What size are you expecting 0.5 0.5 0.5 to be?

Categories

Find more on Operators and Elementary Operations in Help Center and File Exchange

Asked:

on 6 Apr 2023

Edited:

on 6 Apr 2023

Community Treasure Hunt

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

Start Hunting!