Define a Matrix 3x3 using matlab

5 views (last 30 days)
Nemo
Nemo on 20 May 2016
Answered: Naga on 24 Sep 2024
I'm tryin to define a 3x3 matrix using matlab but I get an error: Undefined function or variable 'A'. Here's my code:
J := matrix([[-(l1+q2)*sind(q1)-l3*sind(q1+q2), cosd(q1), -l3*sind(q1+q3)], [(l1+q2)*cosd(q1)+l3*cos(q1+q3), sind(q1), l3*cosd(q1+q3)],[1,0,1]]);
Can someone please help with the syntax?
  1 Comment
Azzi Abdelmalek
Azzi Abdelmalek on 20 May 2016
There is no any variable A in your expression, := is not a Matlab operator, use instead = operator

Sign in to comment.

Answers (1)

Naga
Naga on 24 Sep 2024
Hello Nemo,
It looks like there are a few syntax issues in your MATLAB code. As Azzi mentioned MATLAB does not use := for assignment; instead, it uses =. Additionally, the function to define matrices in MATLAB is simply using square brackets [] without the 'matrix' keyword. Here is
The corrected MATLAB code:
J = [-(l1 + q2) * sind(q1) - l3 * sind(q1 + q2), cosd(q1), -l3 * sind(q1 + q3);
(l1 + q2) * cosd(q1) + l3 * cosd(q1 + q3), sind(q1), l3 * cosd(q1 + q3);
1, 0, 1];

Community Treasure Hunt

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

Start Hunting!