MATLAB: Get value from excel file

get data from excel file

Hi. I random the images into the axes already now. In the excel file I have list the file image name with the image names in the next column. I would like to get the image name in the second row from the excel file and display it in the textbox. For example if I get P1.jpg it will display rock but if I get P2.jpg it will display paper. Can someone please help me? Thank you.
images = {'P1.JPG','P2.JPG','P3.JPG','P4.JPG','P5.JPG','P6.JPG','P7.JPG','P8.JPG','P9.JPG','P10.JPG','P11.JPG','P12.JPG','P13.JPG','P14.JPG','P15.JPG','P16.JPG','P17.JPG','P18.JPG','P19.JPG','P20.JPG','P21.JPG','P22.JPG','P23.JPG','P24.JPG','P25.JPG','P26.JPG','P27.JPG','P28.JPG','P29.JPG','P30.JPG','P31.JPG','P32.JPG','P33.JPG','P34.JPG','P35.JPG','P36.JPG','P37.JPG','P38.JPG','P39.JPG','P40.JPG','P41.JPG','P42.JPG','P43.JPG','P44.JPG','P45.JPG','P46.JPG','P47.JPG','P48.JPG','P49.JPG','P50.JPG','P51.JPG','P52.JPG','P53.JPG','P54.JPG','P55.JPG','P56.JPG','P57.JPG','P58.JPG','P59.JPG','P60.JPG','P61.JPG','P62.JPG','P63.JPG','P64.JPG','P65.JPG','P66.JPG','P67.JPG','P68.JPG','P69.JPG','P70.JPG','P71.JPG','P72.JPG','P73.JPG','P74.JPG','P75.JPG','P76.JPG','P77.JPG','P78.JPG','P79.JPG','P80.JPG','P81.JPG','P82.JPG','P83.JPG','P84.JPG','P85.JPG','P86.JPG','P87.JPG','P88.JPG','P89.JPG','P90.JPG','P91.JPG','P92.JPG','P93.JPG','P94.JPG','P95.JPG','P96.JPG','P97.JPG'};
ix = randi([1,97]);
imagedata = images{ix};
imshow(imagedata);
[num,namePic,raw] = xlsread('DB.xls');

Best Answer

images = {'P1.JPG','P2.JPG','P3.JPG','P4.JPG','P5.JPG','P6.JPG','P7.JPG','P8.JPG','P9.JPG','P10.JPG','P11.JPG','P12.JPG','P13.JPG','P14.JPG','P15.JPG','P16.JPG','P17.JPG','P18.JPG','P19.JPG','P20.JPG','P21.JPG','P22.JPG','P23.JPG','P24.JPG','P25.JPG','P26.JPG','P27.JPG','P28.JPG','P29.JPG','P30.JPG','P31.JPG','P32.JPG','P33.JPG','P34.JPG','P35.JPG','P36.JPG','P37.JPG','P38.JPG','P39.JPG','P40.JPG','P41.JPG','P42.JPG','P43.JPG','P44.JPG','P45.JPG','P46.JPG','P47.JPG','P48.JPG','P49.JPG','P50.JPG','P51.JPG','P52.JPG','P53.JPG','P54.JPG','P55.JPG','P56.JPG','P57.JPG','P58.JPG','P59.JPG','P60.JPG','P61.JPG','P62.JPG','P63.JPG','P64.JPG','P65.JPG','P66.JPG','P67.JPG','P68.JPG','P69.JPG','P70.JPG','P71.JPG','P72.JPG','P73.JPG','P74.JPG','P75.JPG','P76.JPG','P77.JPG','P78.JPG','P79.JPG','P80.JPG','P81.JPG','P82.JPG','P83.JPG','P84.JPG','P85.JPG','P86.JPG','P87.JPG','P88.JPG','P89.JPG','P90.JPG','P91.JPG','P92.JPG','P93.JPG','P94.JPG','P95.JPG','P96.JPG','P97.JPG'};
ix = randi([1,97]);
imagedata = images{ix};
imshow(imagedata);
[num,namePic,raw] = xlsread('DB.xls');
%%get the description of image
image_names = namePic(2:end,1) ; % image names
image_desc = namePic(2:end,2) ; % image description
pos = 1:length(image_names) ; % serial number of images of excel
idx = strcmpi(images(ix),image_names) ; % compare the image names
idx = pos(idx) ; % get the position of image name
title(image_desc(idx)) ; % title of the image as decription