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

Step function using matlab

  1. Feb 5, 2012 #1
    step function using matlab :D

    hey guyzzzz
    i got a problem with this matlab program ...um a beginner in using matlab :D...and my professor insists to solve the attached problem with matlab without using "if statement" and in one line command and to plot the current versus the energy...may anyone help plz :D
     

    Attached Files:

    • prob.jpg
      prob.jpg
      File size:
      18.7 KB
      Views:
      141
  2. jcsd
  3. Feb 6, 2012 #2
    Re: step function using matlab :D

    Explore this as a learning exercise.

    Code (Text):
    A = 1:10  % Copy+Paste this line

    A =

         1     2     3     4     5     6     7     8     9    10

    class(A)  % Copy+Paste this line

    ans =

    double

    idx = A<=5   % Copy+Paste this line

    idx =

         1     1     1     1     1     0     0     0     0     0

    class(idx)   % Copy+Paste this line

    ans =

    logical

    A(idx)    % Copy+Paste this line

    ans =

         1     2     3     4     5

    A(idx)=0    % Copy+Paste this line

    A =

         0     0     0     0     0     6     7     8     9    10
    That should give you enough to do your problem.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Step function using matlab
Loading...