Reputation:
I have 5 matrices of different dimensions (n = 256, 512, 1024, 2048, and 4096) and I was wondering how I could store them in an array (which I could iterate through in a for loop later). I tried just doing {\tt matArray = [A B C D E];} but it said that horzcat needed dimensions that agreed. I also tried using cells but I might not be using them correctly because I'm getting an error that says, 'Conversion to cell from double is not possible'. Here is the piece of code that's giving me an error:
A=randi(9, 256);
B=randi(9, 512);
C=randi(9, 1024);
D=randi(9, 2048);
E=randi(9, 4096);
matArray=cell(1,5);
matArray(1)=A;
matArray(2)=B;
matArray(3)=C;
matArray(4)=D;
matArray(5)=E;
Do you guys have any idea what's going on? Thanks in advance.
Upvotes: 2
Views: 6031
Reputation: 46435
Use matArray{1}=A;
That is how you address a cell element. You can reference it later with matArray{1}
etc.
You could initialize matArray
with all the matrices with a simple statement:
matArray = {A; B; C; D; E};
Note the use of curly braces for cell initialization.
Upvotes: 5
Reputation: 10708
You need semicolons to do vertical concatenation.
matArray = [A; B; C; D; E];
Upvotes: -1