Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
help in store matrix in every run of for loop

Subject: help in store matrix in every run of for loop

From: mahdi roozbhani

Date: 21 Dec, 2010 10:05:10

Message: 1 of 3

How can I store all of the matrix x and y in in each time implementation of 'for loop'.

clc
clear

    
o=3/1000;
 for i=0:1000

THETA=linspace(0,2*pi,1000);
RHO=ones(1,1000)*(3-(i*o));
[x,y] = pol2cart(THETA,RHO);
 end

Subject: help in store matrix in every run of for loop

From: Sean de

Date: 21 Dec, 2010 16:07:24

Message: 2 of 3

"mahdi roozbhani" <m.m.roozbahani@gmail.com> wrote in message <iepu4m$ils$1@fred.mathworks.com>...
> How can I store all of the matrix x and y in in each time implementation of 'for loop'.
>
> clc
> clear
>
>
> o=3/1000;
> for i=0:1000
>
> THETA=linspace(0,2*pi,1000);
> RHO=ones(1,1000)*(3-(i*o));
> [x,y] = pol2cart(THETA,RHO);
> end

Well you could preallocate x,y, as zeros(1001,1000) and then set x(i,:) and y(i,:) equal to your pol2cart expression in the loop.
x = zeros(1001,1000);
y = x;
THETA =linspace(0,2*pi,1000);
ones_1_1000 = ones(1,1000);
for ii = 0:1000
    [x(ii,:),y(ii,:)] = pol2cart(THETA,ones_1_1000*(3-(ii*3/1000)));
end

But that's boring!

[x y] = pol2cart(repmat(linspace(0,2*pi,1000),[1001,1]),bsxfun(@times,ones(1,1000),(3-(((0:1000).').*3/1000))));

Subject: help in store matrix in every run of for loop

From: tulika Roy

Date: 31 Dec, 2012 13:09:22

Message: 3 of 3

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <ieqjbr$7er$1@fred.mathworks.com>...
> "mahdi roozbhani" <m.m.roozbahani@gmail.com> wrote in message <iepu4m$ils$1@fred.mathworks.com>...
> > How can I store all of the matrix x and y in in each time implementation of 'for loop'.
> >
> > clc
> > clear
> >
> >
> > o=3/1000;
> > for i=0:1000
> >
> > THETA=linspace(0,2*pi,1000);
> > RHO=ones(1,1000)*(3-(i*o));
> > [x,y] = pol2cart(THETA,RHO);
> > end
>
> Well you could preallocate x,y, as zeros(1001,1000) and then set x(i,:) and y(i,:) equal to your pol2cart expression in the loop.
> x = zeros(1001,1000);
> y = x;
> THETA =linspace(0,2*pi,1000);
> ones_1_1000 = ones(1,1000);
> for ii = 0:1000
> [x(ii,:),y(ii,:)] = pol2cart(THETA,ones_1_1000*(3-(ii*3/1000)));
> end
>
> But that's boring!
>
> [x y] = pol2cart(repmat(linspace(0,2*pi,1000),[1001,1]),bsxfun(@times,ones(1,1000),(3-(((0:1000).').*3/1000))));

how can i store and access old array after run command ?we can hold on figure but we can not hold that array who plotted the figure.this is a part of my program.

ipv=[]; vpv=[];
              for i=1:1:2
                  Ipv(:,1)=i;
                  Vpv(:,1)=i;
                  
                  run=sim('pv_model');
                  
                  ipv=[ipv,Ipv];
                  vpv=[vpv,Vpv];
       

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us