Difficulty in Concatenating the matrix and preallocation- I would like to concatenate marix output generated from each iteration one after the other but my matlab code add up matrix each time from the beginning. How can i change it.Please help-Thanks
Show older comments
Data1=('uComponent.txt');
Data2=('vComponent.txt');
Data3=('wComponent.txt');
u=importdata(Data1);
v=importdata(Data2);
w=importdata(Data3);
[r1,c1]=size(u)
TM=[];T=[];Mu=[];Mv=[];Mw=[];
k=0;
x=10.0658; y=14;
x01=-4.2757; y01=-1.376;
[M,N]=myfun1(x,y,x01,y01);
R=reshape(M,5,6);
S=reshape(N,5,6);
W= [-pi -pi*3/4 -pi/2 -pi*1/4 pi/4 pi/2 pi*3/4 0];
for i=1:27:r1;
M1=u(i+13:i+17,7:12);
M2=v(i+13:i+17,7:12);
M3=w(i+13:i+17,7:12);
for D= 0:9:27
[xn,yn]=pol2cart(W,D);
Z1=interp2(R,S,M1,xn,yn);
Mu=vertcat(Mu,Z1);
end
for D=0:9:27;
[xn,yn]=pol2cart(W,D);
Z2=interp2(R,S,M2,xn,yn);
Mv=vertcat(Mv,Z2);
end
for D=0:9:27;
[xn,yn]=pol2cart(W,D);
Z3=interp2(R,S,M3,xn,yn);
Mw=vertcat(Mw,Z3);
end
T=[T;Mu;Mv;Mw];
k=k+1;
end
My questions are: How can i preallocate memory in case of T, Mu,Mv and Mw? It seems size of Mu, mv and Mw keeps on increasing for each iteration of i, althouhg the size of M1, M2 and M3 stays the same. How can i change the code so that i can the size of Mu,Mv and Mw stays the same for each iteration for i, and just changes the value as the value of M1,M2 and M3 changes. Thank you in advances. All tips and help will be appreciated.
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!