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)
Show older comments
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
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.
Answers (2)
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
Shannon Wagoner
on 23 Feb 2020
can you go into detail on using fprintf to get column headers with more formatted appearance?
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.
0 Comments
See Also
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!