How to insert image file name in listbox and show preview?
2 ビュー (過去 30 日間)
古いコメントを表示
I want to populate my matlab gui listbox with my images file name. And once user clicks on the file name, they can preview the image. Why do I get this error - 'Cell contents assignment to a non-cell array object.'? So, all I have now is an empty listbox. I don't see anything wrong with my code.
% in openingFCN:
files = dir(fullfile(pwd,'Folder','*.jpg'));
for x = 1 : length(files)
handles.images{x} = imread(fullfile(pwd,'Folder',files(x).name));
end
set(handles.listbox1,'string',{files.name});
% in listbox1 Callback:
handles.output = hObject;
index = get(handles.listbox1,'value');
imshow(handles.images{index});
guidata(hObject, handles);
0 件のコメント
採用された回答
Guillaume
2015 年 5 月 15 日
Which line is giving you this error?
Possibly, this one:
handles.images{x} = imread(fullfile(pwd,'Folder',files(x).name));
which would indicate that handles.images already exists and is not a cell array.
In which case,
handles.images = cell(1, numel(files));
for x = 1 : numel(files)
%... rest of the code
should solve the problem.
It's a good idea to predeclare your arrays in matlab anyway (although for cell arrays it's not going to make much different to performance).
5 件のコメント
Guillaume
2015 年 5 月 15 日
@saturday. The 'conversion to double from cell' error must be when you read the cell content so does not come from the line you've shown.
Please show the line responsible for the error.
@Stephen, of course resizing large cell arrays will have a major effect on memory / performance. On the other hand resizing a small cell array has a much smaller impact than resizing say a char array, since the only thing that is copied are the pointers to the cell contents rather than the content themselves.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Migrate GUIDE Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!