简体   繁体   中英

Storing different sized matrices into array in MATLAB

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 = [ABCDE];} 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.

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.

您需要分号来进行垂直串联。

matArray = [A; B; C; D; E];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM