How should I write a script that generates a table containing the sin and cos values for X between 0° and 90°, in 1° increments?

28 views (last 30 days)
I am a fairly new user to matlab and need some help creating this table. There should be three columns labeled x, sin(x), and cos(x) and 91 rows for the values of x (0 through 90), sin(x), and cos(x). Thanks!
  2 Comments
Les Beckham
Les Beckham on 24 Sep 2015
What have you tried so far? Are you getting some error messages? What are they?
The folks that answer questions on Matlab Answers are happy to help when a question indicates that you have really tried to solve a problem and need help with specific issues. Asking them to do the work for you is not likely to get you much help. These people are busy, too.
Marc Mezzacappa
Marc Mezzacappa on 25 Sep 2015
Edited: Marc Mezzacappa on 25 Sep 2015
Sorry about that. I realize I was not too clear in what my actual problem was and I apologize for that. So I was originally able to actually create a table, but the issue is that it does not display the entire columns. Instead it does this: x = 0 : 90;
y1 = sin(x);
y2 = cos(x);
t = table(x, y1, y2)
>> test2_5
table =
x y1 y2
_____________ _____________ _____________
[1x91 double] [1x91 double] [1x91 double]
I need every value listed as well as the second two columns to be labeled as sin(x) and cos(x) instead of y1 and y2. Thanks!

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 25 Sep 2015
You need to make all columns in your table column vectors not row vectors. Try it this way:
x = (0 : 90)'; % Transpose row vector to form column vector.
y1 = sin(x);
y2 = cos(x);
t = table(x, y1, y2)
Now x is a column vector and consequently y1 and y2 will be also, and since they all have the same number of rows, 91, table() will be happy.
  3 Comments

Sign in to comment.


Image Analyst
Image Analyst on 24 Sep 2015
Edited: Image Analyst on 24 Sep 2015
Some hints:
x = 0 : 90;
threeColumntable = table(col1Vector, col2Vector, col3Vector);
and look at the functions sind() and cosd(). No for loop is needed - sind() can accept a whole vector of a bunch of numbers, not only one single scalar number.

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!