Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Question on Matlab

  1. Jan 7, 2008 #1
    Hello,
    I am new to Matlab and got a question to ask.

    I have created a .m file which plots a cosine graph.
    For simplicity, say
    time=0:T/999:T;
    x=cos(2*pi*time);
    plot(time,x);

    Then this will create a plot with cos(2piT) with domain of 0~T.

    I will like to export this to other .m file so the file can read this graph and calculate the frequency of graph.
    But I'm stuck as how I can export this graphical data to other .m file.

    Because if I just lookup data on x, it will just give out an array of 1000 values and not knowing its domain(time), I can not calculate the frequency.

    Hope this makes sense.

    Will appreciate your helps!
     
  2. jcsd
  3. Jan 8, 2008 #2

    mda

    User Avatar

    a couple of points:

    Firstly the best way to do this is to write the function so that it returns time & x.

    Put this at the very top of your m file
    Code (Text):

    function [x,time]=mygenfunc(T)
     
    Save the file as mygenfunc.m

    Then call the function from somewhere using
    Code (Text):

    [x,time]=mygenfunc(1);
     
    for example.

    If you are dead set on using the graph then the following code may be of use:
    Code (Text):

    c=get(gca,'Children');
    time=get(c,'XData');
    x=get(c,'YData');
     
     
    Last edited: Jan 8, 2008
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Question on Matlab
  1. MATLAB questions (Replies: 0)

  2. MATLAB question (Replies: 2)

  3. MATLAB question (Replies: 1)

  4. Matlab question (Replies: 2)

  5. Matlab question (Replies: 10)

Loading...