Search code examples
matlabmatrixcreate-table

Creating Dynamic matrices in MATLAB


I have a problem with defining some matrices in MATLAB. I get three numbers x,y,z as an input from user, then I want to create y-1 empty matrices. For example consider x = 3, y = 4, and z = 2. The required y-1 matrices M1, M2, and M3 are:

size(M1) = [3,4] ~ [x,y]

size(M2) = [4,4] ~ [y,y]

size(M3) = [4,2] ~ [y,z]

The parameters x,y are not known before running the program. If y was 5, the matrices were:

size(M1) = [3,5] ~ [x,y]

size(M2) = [5,5] ~ [y,y]

size(M3) = [5,5] ~ [y,y]

size(M4) = [5,2] ~ [y,z]

Indeed the main problem is that the number of matrices is an input. Please guide me on how I can create a function loop to define this matrices.


Solution

  • X = input('Enter X please: '); 
    Y = input('Enter Y please: '); 
    Z = input('Enter Z please: '); 
    Cells={}
    Cells{1}=zeros(X,Y);
    for i=2:Y-1
     Cells{i}=zeros(Y,Y);   
    end;
    Cells{Y-1}=zeros(Y,Z);