MATLAB: How can i select images out of the cells

blackjackimage processing

I have to create blackjack for a exercise and I had to come up with a way to assign cards a numerical value. I therefore have made a "deck" of 52 cells, each cell being 1 x 2 containing an image(rgb) and a numerical value which matches that card e.g. 2 of hearts = 2. The issue im having is Matlab won't let me select the image via imshow out of the cell.
deckcan =
Columns 1 through 9
{1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell}
Columns 10 through 18
{1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell}
Columns 19 through 27
{1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell}
Columns 28 through 36
{1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell}
Columns 37 through 45
{1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell}
Columns 46 through 52
{1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell}
I'm getting this error
>> >> imshow(deckcan{1}(2)) Error using imageDisplayValidateParams Expected input number 1, I, to be one of these types:
double, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64, logical
Instead its type was cell.
Error in imageDisplayValidateParams (line 11) validateattributes(common_args.CData, {'numeric','logical'},…
Error in imageDisplayParseInputs (line 78) common_args = imageDisplayValidateParams(common_args);
Error in imshow (line 219) [common_args,specific_args] = …
The image is the first element of the cell.
Ultimately i want to use it in a for loop i have made to select a random card out of the deck.

Best Answer

According to you, the image is the first element of the cell, so I'm not sure why you're passing 2 as in index to start with. Secondly, to access the element of a cell use {}. So it should be:
cardindex = 12; %for example
imshow(deckcan{cardindex}{1})
cardvalue = deckcan{cardindex}{2};
Personally, I would have made deckcan a 52*2 cell array, rather than a 1*52 cell array of 1*2 cell arrays. The former would be accessed with:
imshow(deckcan{cardindex, 1});
cardvalue = deckcan{cardindex, 2};