how to store new matrix on the old one

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

What is A? Can you post some self-contained code that we can just try to run, which will exhibit the error?
A is [1 1;1 2]
and m and E?
Show the error message in its entirety in the context of the run w/ the above definitions.
m=3;E=[];NewZ=[];
when I run the program I got this error In an assignment A(I) = B, the number of elements in B and I must be the same.
what I want to keep the values of matrix Z and use the values of NewZ instead of each time.
thank you for sharing your ideas.
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
NewZ is a new version of Z ,and I need to keep it aside by itself. at the end I will have m numbers of NewZ. Yes, I'll have an array but I don't know how to save it under the same name and reuse it.

Sign in to comment.

 Accepted Answer

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.

2 Comments

Thank you a good suggestion, you mean for k=1:m, for j=1:4, for i=1:4, C=A*[i;j]; [x]=mod(C(1),4)+1; [y]=mod(C(2),4)+1; Tem=[Tem [x,y]]; end; end; Tem=[]; end;
so I need m times from the Tem vector and I don't know how to write it.Could you please help me with that.
Really I like your efficient way to carry out the procedure.
I will have different orders for the items of Z with each iteration, I need to store each z in an array because I need them for advance process,but I don't know how to do that. Please help.
In this solution I will not have all the copies of Z, so the problem is how to store all the copies in an array.

Sign in to comment.

More Answers (0)

Tags

Asked:

on 25 May 2014

Commented:

on 26 May 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!