Question:

Putting different matrices in a shell in MATLAB?

by  |  earlier

0 LIKES UnLike

I have some matrices with different sizes but same dimensions, how can I put them all in a mother object so that e.g. A[B] recalls matrix B and A[C] recalls matrix C etc.

 Tags:

   Report

1 ANSWERS


  1. Easiest way is to use cell array. If you have matrices A, B and C that all have different sizes you can put them into one cell array using:

    my_cell_array = {A,B,C};

    And accessing third index in matrix B:

    my_cell_array{2}(3)

    You can also use structs:

    my_struct.matrix_A = A;

    my_struct.matrix_B = B;

    my_struct.matrix_C = C;

    Now you could access first index in matrix A using:

    my_struct.matrix_A(1)

    or by using dynamic fieldnames:

    my_struct.('matrix_A')(1) %actually im not so sure about this :) check Doug's blogpost

    Keep in mind that it might not be very memory efficient to use cell arrays or structs. There is probably more information about memory issues somewhere.

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.