I want to store two variables in an array or list in a loop to collect all my x an y, something like the append function in python, can anyone help me.

Not sure exactly what you're asking... but you could make a list of tuples list:

my_list = [ (0,0),
            (0,1),
            (1,1),
            (1,2) ]

? Is that what you're asking?

I am thinking of:

"Python"

x_values = ()
y_values = ()

for i in range(n);
    x = i
    y = i+1
    x_values.append(x)
    y_values.append(y)

# Optional
x_and_y = zip(x_values,y,values)

I am new to programming so the code might be wronge, but this is what I am trying to do in Matlab.

I don't really understand what you're asking... Can you clarify what you need help with?

I want to append some values to a list in MATLAB.

x_values = []
y_values = []

for i in range(n);
    x = i
    y = i+1
    x_values.append(x)
    y_values.append(y)

How are you wanting to arrange your x and y values? What you have done is correct if you want to create a list of x's and a list of y's whos values are 1 greater than the corresponding x.

Ah I think you want to do it in M-code. I think you could do this:

x = 0:1:n 
y = 1:1:n+1
% where n would be as far as you would want to go. The syntax is in the form STARTINGNUMBER:INCREMENT:FINALNUMBER

I have two different functions which calculates the speed numerically, what I want to do is plot the difference between them against delta-x usinf Matlab


In Python:

N = [5,8,10,12]
deltax-list = []
speed-difference-list = []

for n in N:
     dx = pi./(n-1)
     deltax-list.append(dx)
     s1 = function1(n)
     s2 = function2(n)
     s = abs(s1-s2)
     speed-difference-list.append(s)

Is there an append function in Matlab or some other way to send values in to a list or array?

Thanks, it works perfect in Matlab.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.