From: SPANKY on
So basically I have to graph the values that are calculated through a for loop, but the problem is that I am having trouble in storing the values that are produced in the for loop. Any advice would be great!
From: SHark on
first create a matrix (with an arbitrary initial value):
A = [0];

then in your for loop
for....
<your calculations>
A = [A;x]
end

where x is the value you calculated in your loop.




"SPANKY " <upwhat96(a)yahoo.com> wrote in message <hqa9j3$raj$1(a)fred.mathworks.com>...
> So basically I have to graph the values that are calculated through a for loop, but the problem is that I am having trouble in storing the values that are produced in the for loop. Any advice would be great!
From: Matt Fig on
What is the form of the points? Vectors? Scalars? Is there a matching between points, as in each time through the loop you calculate an x and a y? You could use a regular array or a cell array. Which to choose will depend somewhat on the data.
From: SPANKY on
The form of the points is a scalar. It kind of looks like this....
for n=1:100
<calculation which is a function of the value of n>
end
This is the part where I am having trouble in that i cant store the values calculated for each value of n.The graph is my calculated value versus the value n.
"Matt Fig" <spamanon(a)yahoo.com> wrote in message <hqab88$rgr$1(a)fred.mathworks.com>...
> What is the form of the points? Vectors? Scalars? Is there a matching between points, as in each time through the loop you calculate an x and a y? You could use a regular array or a cell array. Which to choose will depend somewhat on the data.
From: Matt Fig on
% Put this outside loop in case you later change it to include neg. nums or 0 or fractions.
n = 1:100;
T = zeros(1,length(n)); % Pre-allocate the array.

for ii = 1:length(n)
T(ii) = n(ii)^2 - n(ii); % Fill the array. Notice the index into n.
end

plot(n,T)