Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Storing the value of a variable
Replies: 1   Last Post: Feb 10, 2013 3:30 AM

 Nasser Abbasi Posts: 6,677 Registered: 2/7/05
Re: Storing the value of a variable
Posted: Feb 10, 2013 3:30 AM

On 2/9/2013 9:22 PM, Subash Padmanaban wrote:
> for k= 55 : 65
> level= graythresh(frame);
> fig=im2bw(frame,level);
> imshow(fig);
> numberofpoints=1;
> [x y]=ginput(numberofpoints);
> plot(x,y);
> end
>
> My problem is that, I want to store the values of x and y in an
> array and later plot it. How do I go about with this? Also, every
> time the number of frames will not be the same.
>

You know the total size of x and y needed? It is the
length of each loop * numberofpoints. Hence you
can preallocate a matrix to store then in.

--------------------------
close all;
N = 3;
numberofpoints = 4;
data = zeros(numberofpoints,2,N); %store all points

for i=1:N
[data(:,1,i) data(:,2,i)] = ginput(numberofpoints);
end

%get the points out and plot them
X = permute(data,[1 3 2]);
X = reshape(X,[],size(data,2),1)
plot(X(:,1),X(:,2),'ro')
--------------------------

--Nasser