Info

This question is closed. Reopen it to edit or answer.

How to generate a Sine with parameter input and output pre determined?

1 view (last 30 days)
How to generate a Sine with parameter input and output pre determined?
Hello, I need to generate 3 million files based cuvas with values X, Y (Time, Amplitude) of type Float for both.
How can I make a function that I indicate the time, amplitude, and get a txt file of data for each curve?

Answers (2)

Nir Rattner
Nir Rattner on 4 Aug 2014
Edited: Nir Rattner on 5 Aug 2014
Given a sinusoid of the form “y = A * sin(w * x)”, I’m assuming you want the function to take “A” and “w” as parameters. The code below also assumes that “x” will span one period. The results will be saved as a text file based on the given name “outputFile”.
Edit: Based on your comment, it seems that you want to be able to control the amplitude, period, start time, and end time. In that case it seems like the following function should give you the correct results. "A" represents the amplitude, "T" represents the period, and "t" represents a vector that contains all of the time values.
function sineFunction(A, w, t, outputFile)
y = A * sin(t * 2 * pi / T);
save(outputFile, 't', 'y', '-ASCII');
Here is the function call you would make for the example you gave:
sinFunction(180, 10, 0 : 0.01 : 5, 'out.txt');

Crash
Crash on 5 Aug 2014
Hello, very cool your example ... how could I do to create parameters start and end of the curve? I'm just trying to generate pre-defined curves to Location XYZ and Rotation XYZ of a program that creates games ... Within the program I can create a timeline for animating objects plus I have no way to create a timeline dynamically ... How am making the animations to move the BPM of a song, I need to create some presets for each BPM ... So for example:
Set the Curve Editor I can create curves using 2 Parameters:
X = Horizontal Time Y = Vertical Float - that can relate to any component of the game, like an object and set XY or Z.
So in the case so I can create a preset that move any object type in a video camera 180 degrees and then return to Zero position in 5 Seconds I need to create a curve with 3 Key Frame
0.0 (In Time Zero / Zero Position In) - Start 2.5,180 (2.5 Seconds In the Camera will be on 180th) 5.0 (In 5 Seconds camera will be Zero)
So I would create some way that I can put a keyframe at Time Zero and the Zero position After another keyframe at time 2.5 seconds, and 180 Degrees And then return to Zero position ....
So I could create a lot of csv files for each preset and then import the curves to create the timeline with presets and rotation for the BPMs of songs that are being played at the time ....
Sorry friend, I think I expressed myself badly in my first question ... I still do not have many ideas of how this function would be taken from KeyFrames ....
Thank you for your help

Community Treasure Hunt

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

Start Hunting!