MATLAB: How to save variables and put them in a vector

arrayvector

I have this code in which i input a value, let's call it x. The code runs, and afterwards it stores a value called y. For each different x there's another y. What i want to do is each time i input an x it stores its value on a vector and the value from y on another vector so i can later plot them together.

Best Answer

Example:
num_runs = 10;
all_x = zeros(num_runs, 1);
all_y = zeros(num_runs, 1);
for K = 1 : num_runs
x = randi([-K K], 1, 1);
y = x.^2;
all_x(K) = x;
all_y(K) = y;
end