您有这个代码,我不知道如何将输出结果与每个像素放在一起。我认为输出代码没有很好地定义。
编辑:
我将尝试解释代码:
% I have an image
imagen1=imread('recor.tif');
imagen2= double(imagen1);
band1= imagen2(:,:,1);
% I preallocate the result (the image size is 64*89*6)
yvan2= zeros(61,89,1);
% For every pixel of the image, I want to get one result (each one is different).
for i = 1 : nfiles
for j = 1 : nrows
for i = 1:numel(band1)
% I'm doing this because I've to multiply the results of this interpolation with that result a2ldb1y= ldcm_1(:,1). This vector has a length of 2151x1 and I need to muliply the result of the interpolation for (101:267) position on the vector, this is the reason because I'm doing the interpolation since 101 to 267 (also because I don't have that values).
interplan= interp1(van1,man2,t2,'spline');
ma(96) = banda1a(i); % I said 96, because I want to do an interpollation
end
van1= [101 96 266]';
mos1= ma(134);
van2= [0 pos1 0];
t= 101:267;
t2= t';
xi= 101:1:267;
xi2=xi';
interplan= interp1(van1,van2,t2,'spline');
% After this, I 'prepare' the vector.
out=zeros(2151,1)
out(101:267) = interplan;
% And then, I do all this operation (are important for the result)
a2ldb1y= ldcm_1(:,1);
a2ldsum_pesos1= sum(a2ldb1y);
a2l7dout1_a= a2ldb1y.*out;
a2l7dout1_b= a2l7dout1_a./a2ldsum_pesos1;
a2l7dout1_c= sum(a2l7dout1_b);
% And the result a2l7dout1_c I want it for every pixel (the results are different because every pixel has a different value...)
**yvan2(:,:,1)= [a2l7dout1_c];**
end
end
提前致谢,
答案 0 :(得分:0)
我在黑暗中拍摄,但我认为你正在寻找:
yvan2(i, j, 1)= a2l7dout1_c;
而不是:
yvan2(:,:,1)= [a2l7dout1_c];
因此,在完成循环后,您的输出应存储在变量yvan2
中。
代码中的一些问题:
为什么有两个循环使用相同的迭代变量i
?由于i
被两个for
循环修改,因此您的计算可能不正确。
为什么你甚至需要第二个循环?每次迭代都会超过前一次迭代设置的ma(134)
的值。你可以用以下代码替换整个循环:
ma(134) = banda1a(numel(band1))
您不应该使用名称i
和j
来表示循环变量。它们已经为虚构单元保留(即sqrt(-1)
),因此MATLAB需要额外的处理时间来进行名称解析。您宁愿使用其他循环变量名称,甚至是ii
和jj
。