-2

I am trying to print a recursive variable using a for loop:

w
i=0;
for i<=10;
    w('i')
end

I am trying to print a simple thing.I have a variable named W and using a for loop from 1 to 10, I want to print w1,w2,w3,w4,w5 etc. How can I do that?

4
  • You might want to read a tutorial on MATLAB, as this is about as basic as it gets. The MathWorks themselves published a good tutorial I can recommend.
    – Adriaan
    Jul 3, 2020 at 8:47
  • What is a "recursive variable"? Also, you really shouldn't be using dynamically-named variables. Use some sort of indexed container, instead, like a vector or array.
    – Cody Gray
    Jul 3, 2020 at 8:49
  • i am sorry i am very new to programming, i took a break from studies and went to non-tech side of things for 3 years, kind of coping up with everything now
    – Rahul
    Jul 3, 2020 at 11:00
  • @CodyGray i couldn't find a more suitable name, i am trying to solve inverse dynamics of a 3 -link serial robot and using recursive newton eulor algorithm for it, if i define every variable by myself the number of variables would be very high and tedious to write individualy, instead i though if i can recursively get these variables printed and slim down the code.
    – Rahul
    Jul 3, 2020 at 11:04

1 Answer 1

0

I think this will work for you:

for i = 1:10
    disp("w"+i)
end

This is the output that I got:

w1
w2
w3
w4
w5
w6
w7
w8
w9
w10
1
  • i tried this and it worked, thank you. i am trying to use these variables to store matrices in a 3-link serial robot.
    – Rahul
    Jul 3, 2020 at 11:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.