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

Changing part of a name of a variable in a for loop

  1. Oct 6, 2012 #1
    changing part of a name of a variable in a "for" loop

    hello everyone!

    let's say i have the equation between two variables: DT10sec= A*T10sec, working in matlab. How can i use a "for" loop to calculate the equation DT20sec= A*T20sec DT30sec= A*T30sec, DT40sec= A*T40sec,... etc

    How can i interfere in just a part of the name of a variable? i would suppose something like the following

    for i=1:5
    DT"i"sec= A* T"i"sec
    end

    but it is not the right symbol
     
  2. jcsd
  3. Oct 6, 2012 #2

    mfb

    User Avatar
    2016 Award

    Staff: Mentor

    Re: changing part of a name of a variable in a "for" loop

    I would use an array. I don't know the matlab syntax, but most programming languages would write this as DTsec[10] or (with a variable i) DTsec[10*i].
     
  4. Oct 6, 2012 #3
    Re: changing part of a name of a variable in a "for" loop

    DT..sec and T..sec are matrices and i m not interested on making an array of matrices. DT is the result from calculations (as T is a known matrix) for different time points and i just want to name my results according to the time point they refer to. But i am looking for a quicker way to do it, using a for loop. Thanks anyway
     
  5. Oct 6, 2012 #4
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Changing part of a name of a variable in a for loop
Loading...