store images in a table
    조회 수: 6 (최근 30일)
  
       이전 댓글 표시
    
Hello,
I have three images and want to store them in a table. I wrote this in command line:
dinfo = dir('*.jpg');
T = table();
for K = 1 : length(dinfo)
filename = dinfo(K).name;
filecontent = imread(filename);
T{filename,1} = filecontent;
end
It gives the error:
To assign to or create a variable in a table, the number of rows must match the height of the table.
Secondly, I want to make my three images equal in size, as we have to make the size of variables in rows equal for tables.
Help needed. Thanks in advance.
댓글 수: 0
답변 (2개)
  Azzi Abdelmalek
      
      
 2016년 5월 4일
        
      편집: Azzi Abdelmalek
      
      
 2016년 5월 4일
  
      Do you mean how to store them in a cell array?
dinfo = dir('*.jpg');
n=numel(dinfo);
T=cell(n,1);
for K = 1 : n
  filename = dinfo(K).name;
  filecontent = imread(filename);
  T{k,1} = filecontent;
end
댓글 수: 1
  Dominik Stolfa
 2024년 9월 28일
				Hi. Your comment quite helped me. Could you please give me advice on how to show this table (plot/put_in_figure/export_to_excel/etc.)?
  Guillaume
      
      
 2016년 5월 4일
        You've created an empty table (no columns or rows) and are then trying to index into it using row names it knows nothing about. Of course, it's not going to work. The fix is to create a table the right size by passing it a cell array the right size, and telling it the names of the rows at the same time:
numimages = numel(dinfo); %numel is safer than length
T = table(cell(1, numimages), 'VariableNames', {'image'}, 'RowNames', {dinfo.name});
for K = 1 : numimage
  ...
Note that your filenames must be valid variable names otherwise your assignment call will fail. It may be safer to use:
T{K, 1} = filecontent
Since the images are held in a cell array there is no requirement that they are the same size. But if you want that, use imresize
댓글 수: 0
참고 항목
카테고리
				Help Center 및 File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


