1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to increment a MATLAB for loop by an arbitrary value?

  1. Jan 22, 2014 #1
    How to increment a MATLAB "for" loop by an arbitrary value?

    I am creating a Matlab program that calculates corresponding temperatures for Celsius, Kelvin, Fahrenheit, and Rankine scales. I want to write my code so that it can handle an arbitrary temperature increment (a user-inputted value).

    Here is my current code (it currently increments by 1 degree Celsius--I want to change this):

    Cstart = -50;
    Cend = 100;
    for Celsius = Cstart:Cend
    Celius = Celsius
    Kelvin = Celsius + 273.15
    Fahrenheit = 1.8.*Celsius + 32
    Rankine = (Celsius+273.15)*1.8
    end
    plot(Celsius,Kelvin,'r')
    hold on
    plot(Celsius,Fahrenheit,'b')
    hold on
    plot(Celsius,Rankine,'g')
    legend('Kelvin','Fahrenheit','Rankine','FontSize',20)
    xlabel('Temperature in Celsius','FontSize',20)
    ylabel('Converted Temperature','FontSize',20)
    title('Equivalent Temperatures','FontSize',20)
    set(gca,'FontSize',20)

    Thank you in advance!
     
  2. jcsd
  3. Jan 22, 2014 #2

    Mark44

    Staff: Mentor

    The syntax for a for loop includes an optional increment expression, like this:
    Code (Text):
    for i = 1.0: 0.1: 10.0
       ...
    end
    The increment expression is the one in the middle between the starting value and the ending value.
     
  4. Jan 22, 2014 #3

    donpacino

    User Avatar
    Gold Member

    kal854 someone has been on yahoo answers..........
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: How to increment a MATLAB for loop by an arbitrary value?
  1. For loops in Matlab (Replies: 22)

  2. MatLab for loops (Replies: 3)

Loading...