Error using reshape To RESHAPE the number of elements must not change. Error in loadFileYuv (line 18) imgYuv(:, :, 1) = reshape(buf, width, height).'; % reshape
    3 次查看(过去 30 天)
  
       显示 更早的评论
    
function [mov,imgRgb] = loadFileYuv(fileName, width, height, idxFrame)
fileId = fopen(fileName, 'r');
subSampleMat = [1, 1; 1, 1];
nrFrame = length(idxFrame);
for f = 1 : 1 : nrFrame
    % search fileId position
    sizeFrame = 1.5 * width * height;
    fseek(fileId, (idxFrame(f) - 1) * sizeFrame, 'bof');
      % read Y component
      buf = fread(fileId, width * height, 'uchar');
      * |imgYuv(:, :, 1) = reshape(buf, width, height).'; % reshape| *  (line 18)
      % read U component
      buf = fread(fileId, width / 2 * height / 2, 'uchar');
      imgYuv(:, :, 2) = kron(reshape(buf, width / 2, height / 2).', subSampleMat); % reshape and upsample
      % read V component
      buf = fread(fileId, width / 2 * height / 2, 'uchar');
      imgYuv(:, :, 3) = kron(reshape(buf, width / 2, height / 2).', subSampleMat); % reshape and upsample
      % normalize YUV values
      % imgYuv = imgYuv / 255;
      % convert YUV to RGB
      imgRgb = reshape(convertYuvToRgb(reshape(imgYuv, height * width, 3)), height, width, 3);
     end
  fclose(fileId);
when i was trying to run the function i was getting error in the line
imgYuv(:, :, 1) = reshape(buf, width, height).';
Kindly help me.
0 个评论
采纳的回答
  Star Strider
      
      
 2014-9-7
        You are not reading what you believe you are reading from your file. I would check the size of ‘buf’ in line 17 (and probably the other such lines as well). (When I simulate Line 18 with known values, I don’t get the error.)
0 个评论
更多回答(0 个)
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Low-Level File I/O 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

