How do i get a element in a matrix that is stored in a cell array?

Hello guys, i have a cell array 1X4 in each cell i have a MXN matrix. I want to get a element(x,y) inside one of the matrix stored in the cell.
Im currently creating 4 matrices outside de array and the looking for the elements.
How can i do this?
Tks in advance.
Leonardo Hermoso

 Accepted Answer

theMatrixInside = yourCellArray{2}; % Use braces to get the array, not a cell.
theElementsValue = theMatrixInside(row, column); % or (y, x)

7 Comments

FYI, please read the FAQ on cell arrays: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F. It gives you a good intuitive idea how to work with these things, which admittedly can be confusing.
I have not made a confusion... What i really want is to get a element of a matrix that is stored inside a cell...
This command is wrong but would be something like this:
A{1}(5,2)
get the (5,2) element of a matrix stored in A{1}
I dont know if this is possible with a single line code.
And i appreciate the help!
I just realized this is not wrong...Tks again
A{1}(5,2) is ok!
Yes, you can do it that shortcut way, though I find it cryptic and hard to understand later so that's why I prefer the two step method. The problem with cell arrays is always figuring out if you need to use braces or parentheses. The rule of thumb is, if it doesn't work one way, then try it the other way. Of course in situations like you point out, it's even more confusing. But it you're happy with that syntax, then go for it.
How to do this for all matrices in cell array using cellfun? I need to extract (2,1) i.e. second row and first column element of all matrices within cell array ?
I don't know. Experiment with it. I rarely use cellfun().

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!