简体   繁体   English

如何修复此错误 position 2 中的索引超出 MATLAB 中的数组边界?

[英]How to fix this error Index in position 2 exceeds array bounds in MATLAB?

I have a problem with this line of code bloop(rj,cj) = J1(i,j) .我对这行代码有问题bloop(rj,cj) = J1(i,j) I tried it a lot and changed the numbers, but the error remains.我尝试了很多并更改了数字,但错误仍然存在。 The Error is Index in position 2 exceeds array bounds bloop(rj,cj) = J1(i,j) .错误是position 2 中的索引超出数组边界bloop(rj,cj) = J1(i,j)

I hope someone has a solution to this problem.我希望有人能解决这个问题。

clc 
clear 
close all
J = imread('logo.jpg'); %discolored image
J1 = im2double(J); %convert image to bouble precise
[r,c] = size(J1); %find size of image
rc = r*c; %151874

%find A inverse
x = [17;121;171];
xT = x';
xxT = x*xT;
inv = pinv(xxT); %find inverse for singular or badly scaled
y = [17;122;114];
yxT = y*xT;
Ainv = yxT*inv;
B = Ainv;

%find color correction
%reshape matrix to 3xn
i = 0;
j = 0;
bloop=zeros(3,50625);
for rj = 1:3 %row
    i = i+1;
    for cj = 1:50625 %cols
        j = j+1;
        bloop(rj,cj) = J1(i,j);
    end
end
[w,t] = size(bloop);
bloop(:,:)
%I(r,c) = BJ(r,c)color correction equation
I = B*bloop; 

Your j doesn't get reset to zero for each rj/i.对于每个 rj/i,您的 j 不会被重置为零。 Move the j = 0 inside the i loop.j = 0移动到 i 循环内。

clc 
clear 
close all
J = imread('logo.jpg'); %discolored image
J1 = im2double(J); %convert image to bouble precise
[r,c] = size(J1); %find size of image
rc = r*c; %151874

%find A inverse
x = [17;121;171];
xT = x';
xxT = x*xT;
inv = pinv(xxT); %find inverse for singular or badly scaled
y = [17;122;114];
yxT = y*xT;
Ainv = yxT*inv;
B = Ainv;

%find color correction
%reshape matrix to 3xn
i = 0;
bloop=zeros(3,50625);
for rj = 1:3 %row
    i = i+1;
    j = 0; 
    for cj = 1:50625 %cols
        j = j + 1;
        bloop(rj,cj) = J1(i,j);
    end
end
[w,t] = size(bloop);
bloop(:,:)
%I(r,c) = BJ(r,c)color correction equation
I = B*bloop; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM