Horzcat Error in 3x3 matrix with multiplication of Matrices

I am attempting to write this 3x3 matrix :
NED=[ -sin(Latty).*cos(Lonny) -sin(Latty).*sin(Lonny) cos(Latty) ; -sin(Lonny) cos(Lonny) 0 ; -cos(Latty).*cos(Lonny) -cos(Latty).*sin(Lonny) -sin(Latty) ];
I am recieving this error
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error in xlxstomat (line 87)
NED=[ -sin(Latty).*cos(Lonny) -sin(Latty).*sin(Lonny) cos(Latty) ; -sin(Lonny) cos(Lonny) 0 ; -cos(Latty).*cos(Lonny) -cos(Latty).*sin(Lonny) -sin(Latty) ];

2 Comments

Works for me:
Latty = pi/6;
Lonny = pi/4;
NED=[ -sin(Latty).*cos(Lonny) -sin(Latty).*sin(Lonny) cos(Latty) ; -sin(Lonny) cos(Lonny) 0 ; -cos(Latty).*cos(Lonny) -cos(Latty).*sin(Lonny) -sin(Latty) ]
NED = 3×3
-0.3536 -0.3536 0.8660 -0.7071 0.7071 0 -0.6124 -0.6124 -0.5000
Sorry for the lack of information ...Latty and Lonny are 62x1 doubles
Latty
38
39
37
40
39
36
39
39
38
40
35
37
38
40
40
37
36
36
39
36
40
35
39
35
39
39
35
38
39
38
37
36
35
37
39
40
36
39
39
38
38
36
36
38
36
36
38
35
40
36
36
36
36
37
38
39
36
35
38
40
36
32
Lonny
-117
-88
-112
-76
-110
-102
-88
-105
-88
-81
-84
-83
-118
-79
-96
-117
-106
-95
-83
-102
-78
-84
-91
-75
-75
-93
-98
-104
-108
-88
-80
-105
-86
-107
-106
-80
-110
-94
-107
-76
-104
-105
-104
-108
-96
-87
-117
-95
-102
-88
-91
-86
-80
-109
-99
-78
-108
-113
-88
-93
-102
0

Sign in to comment.

 Accepted Answer

You've got the scalar zero in there causing the problem. Replace that scalar zero with a vector of zeros the same size as Latty and Lonny.
The result NED will be 186x3.
Latty = [
38
39
37
40
39
36
39
39
38
40
35
37
38
40
40
37
36
36
39
36
40
35
39
35
39
39
35
38
39
38
37
36
35
37
39
40
36
39
39
38
38
36
36
38
36
36
38
35
40
36
36
36
36
37
38
39
36
35
38
40
36
32];
Lonny = [
-117
-88
-112
-76
-110
-102
-88
-105
-88
-81
-84
-83
-118
-79
-96
-117
-106
-95
-83
-102
-78
-84
-91
-75
-75
-93
-98
-104
-108
-88
-80
-105
-86
-107
-106
-80
-110
-94
-107
-76
-104
-105
-104
-108
-96
-87
-117
-95
-102
-88
-91
-86
-80
-109
-99
-78
-108
-113
-88
-93
-102
0];
NED=[ -sin(Latty).*cos(Lonny) -sin(Latty).*sin(Lonny) cos(Latty) ; -sin(Lonny) cos(Lonny) zeros(size(Lonny)) ; -cos(Latty).*cos(Lonny) -cos(Latty).*sin(Lonny) -sin(Latty) ]
NED = 186×3
0.2146 -0.2044 0.9551 -0.9632 0.0341 0.2666 0.2934 0.5727 0.7654 -0.6142 0.4218 -0.6669 0.9629 -0.0426 0.2666 0.1008 -0.9866 -0.1280 -0.9632 0.0341 0.2666 0.2322 -0.9354 0.2666 -0.2962 0.0105 0.9551 -0.5787 -0.4693 -0.6669

4 Comments

Although the answer has been accepted, I think the aim was that each pair [Latty(i),Lonny(i)] should generate its own 3x3 matrix (after converting Latty and Lonny from degrees to radians):
Latty = [
38
39
37
40
39
36
39
39
38
40
35
37
38
40
40
37
36
36
39
36
40
35
39
35
39
39
35
38
39
38
37
36
35
37
39
40
36
39
39
38
38
36
36
38
36
36
38
35
40
36
36
36
36
37
38
39
36
35
38
40
36
32];
Lonny = [
-117
-88
-112
-76
-110
-102
-88
-105
-88
-81
-84
-83
-118
-79
-96
-117
-106
-95
-83
-102
-78
-84
-91
-75
-75
-93
-98
-104
-108
-88
-80
-105
-86
-107
-106
-80
-110
-94
-107
-76
-104
-105
-104
-108
-96
-87
-117
-95
-102
-88
-91
-86
-80
-109
-99
-78
-108
-113
-88
-93
-102
0];
N = numel(Latty);
Latty = deg2rad(Latty);
Lonny = deg2rad(Lonny);
NED = arrayfun(@(Latty,Lonny)[ -sin(Latty).*cos(Lonny) -sin(Latty).*sin(Lonny) cos(Latty) ; -sin(Lonny) cos(Lonny) 0 ; -cos(Latty).*cos(Lonny) -cos(Latty).*sin(Lonny) -sin(Latty) ],Latty,Lonny,'UniformOutput',0)
NED = 62×1 cell array
{3×3 double} {3×3 double} {3×3 double} {3×3 double} {3×3 double} {3×3 double} {3×3 double} {3×3 double} {3×3 double} {3×3 double} {3×3 double} {3×3 double} {3×3 double} {3×3 double} {3×3 double} {3×3 double}
@Torsten: You may be right.
@olivia: Note that you can use sind, cosd for angles in degrees, as an alternative to deg2rad to convert to radians.

Sign in to comment.

More Answers (1)

There is nothing inherently wrong with the matrix you specified (as you can see from the code below).
You'll need to share more information. Can you upload a code snippet and data that will allow us to run the code and reproduce the error? (You can use the paper clip icon in the INSERT section of the toolbar to attach files.)
Please don't just share a description of what is going on.
Latty = pi/3;
Lonny = pi/7;
NED=[ -sin(Latty).*cos(Lonny) -sin(Latty).*sin(Lonny) cos(Latty) ;
-sin(Lonny) cos(Lonny) 0 ;
-cos(Latty).*cos(Lonny) -cos(Latty).*sin(Lonny) -sin(Latty)]
NED = 3×3
-0.7803 -0.3758 0.5000 -0.4339 0.9010 0 -0.4505 -0.2169 -0.8660

Categories

Products

Release

R2022a

Asked:

on 31 Aug 2023

Commented:

on 31 Aug 2023

Community Treasure Hunt

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

Start Hunting!