Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
 
 
主题工具 显示模式
旧 2019-12-10, 20:48   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 MATLAB编码问题

大家好,当我尝试触发下面的函数时,收到了此错误消息。有人可以帮我吗?谢谢!

>> changeYuv('tilt.yuv',352,288,1:40,40); ??? Index exceeds matrix dimensions. Error in ==> changeYuv at 32 j=histogram(imgYuv(:,:,1,k+1)); >> [x,y,z,a]=size(imgYuv) x = 288 y = 352 z = 3 a = 40 源代码:

function [imgYuv, S]= changeYuv(fileName, width, height, idxFrame, nFrames) % load RGB movie [0, 255] from YUV 4:2:0 file 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,f) = reshape(buf, width, height).'; % read U component buf = fread(fileId, width / 2 * height / 2, 'uchar'); imgYuv(:, :, 2,f) = kron(reshape(buf, width / 2, height / 2).', subSampleMat); % reshape and upsample % read V component buf = fread(fileId, width / 2 * height / 2, 'uchar'); imgYuv(:, :, 3,f) = kron(reshape(buf, width / 2, height / 2).', subSampleMat); % reshape and upsample %histogram difference of Y component for k=1:(nFrames-1) h=histogram(imgYuv(:,:,1,k)); j=histogram(imgYuv(:,:,1,k+1)); X=abs(hj)/256; S(k)=sum(X); end end fclose(fileId);

回答:

在外循环的每次迭代中,您似乎在从空开始的第4维imgYuv增长1。但是您的内部循环始终从1循环到nFrames-1 。因此,在我看来,您似乎正在尝试超出imgYuv的范围。

无关紧要的是,增长这样的数组通常非常缓慢。您最好在开始之前初始化imgYuv ,即imgYuv = zeros([height,width,3,nFrames]) 。



更多&回答...
poster 当前离线   回复时引用此帖
 


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 20:34


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.