How to make an array that the elements are matrix

Hello, I need to do something like a structure where the elements are matrix (3x3):
graph.frontier = [[3x3],[3x3],[3x3],[3x3]]; %and so on
where I would like to append any new element to graph.frontier, so I can use an index to work with it.
I've tryed this:
graph.frontier = [];
initial_state = [7,2,4;5,0,6;8,3,1];
graph.frontier = append(initial_state);
But it didn't work. I'll use this to implement a BFS algo to solve a 8-tile puzzle.
Any ideias?

Answers (1)

Maybe use a cell array? E.g.,
graph.frontier = {[3x3],[3x3],[3x3],[3x3]};
You can then get at the matrices with curly braces, e.g. graph.frontier{1}

3 Comments

That worked, but how can I "append" an matrix to the structure? I mean, without saying the position of the new element, it just go to the last position.
Like:
graph.frontier{1} = initial_state;
graph.frontier = append (next_state);
So it would look like:
graph.frontier = {[initial_state],[next_state]}
I'm sorry for those newbie questions
graph.frontier(end+1) = {next_state};

This question is closed.

Asked:

on 3 May 2019

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!