how to store new matrix on the old one
5 views (last 30 days)
Show older comments
I have a array Z(4,4) such as
[1:4;
5:8;
9:12;
13:16].
I would like to change the order of the matrix and store in a same name as Z with new version;this for the first iteration. for the second iteration; I want to use the previous version and do the same changes on the order to get new one.keep doing this for m iteration.
for k=1:m,
D=[];
for j=1:4,
for i=1:4,
C=A*[i;j];
[x]=mod(C(1),4)+1
[y]=mod(C(2),4)+1
D=[D;Z(x,y)];
end;
E=[E,D];D=[];
end;
NewZ(k)=E;E=[];
Z=NewZ;
end;
always I get this error: Subscripted assignment dimension mismatch.
Please I need a help.
6 Comments
dpb
on 25 May 2014
Don't know if it will produce what you expect or not, but the error comes from
NewZ(k)=E;
where you're trying to store an array in an element. Perhaps what you're looking for is
NewZ=[NewZ;E]; E=[];
to concatenate the E onto NewZ
Accepted Answer
Roger Stafford
on 25 May 2014
To accomplish what you appear to have in mind you would need to modify your code to:
for k=1:m,
E=[];
for j=1:4,
D=[];
for i=1:4,
C=A*[i;j];
[x]=mod(C(1),4)+1;
[y]=mod(C(2),4)+1;
D=[D;Z(x,y)];
end;
E=[E,D];
end;
Z=E;
end
There are more efficient ways of carrying out this procedure. For example, you could pre-calculate all sixteen x,y pairs (which don't depend on Z) and then carry out the m transformations more quickly.
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements 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!