Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Performance 在将矩阵转换为向量时获得更好的性能_Performance_Matlab - Fatal编程技术网

Performance 在将矩阵转换为向量时获得更好的性能

Performance 在将矩阵转换为向量时获得更好的性能,performance,matlab,Performance,Matlab,处理图像时,通常包括3层(RGB)。为了进行一些计算,我需要将图像的每一层转换为一个向量 I1 = ones(70,50,3); % the first image I2 = 0.4 * ones(70,50,3); % the second image for dd = 1:3 ILayer1 = I1(:,:,dd); ILayerLinear1 = ILayer1(:); ILayer2 = I2(:,:,dd); ILayerLinear2 =

处理图像时,通常包括3层(RGB)。为了进行一些计算,我需要将图像的每一层转换为一个向量

I1 = ones(70,50,3);       % the first image
I2 = 0.4 * ones(70,50,3); % the second image
for dd = 1:3
    ILayer1 = I1(:,:,dd);
    ILayerLinear1 = ILayer1(:);
    ILayer2 = I2(:,:,dd);
    ILayerLinear2 = ILayer2(:);
    comp = ILayerLinear1 * ILayerLinear1.';
end
在这里,我用一个非常简单的计算替换了主要的计算部分,但这不是重点。 有没有更好的方法不重复矩阵到向量的转换,或者更有效?因为它可能在代码中发生多次

function V = I2V(I)
[r,c,d] = size(I);
V = zeros(d,r*c);
for dd = 1:d
    layer = I(:,:,dd);
    V(dd,:) = layer(:);
end
end
更新:

我还可以如下定义一个函数来传递图像和检索向量,但它仍然不能改进代码

function V = I2V(I)
[r,c,d] = size(I);
V = zeros(d,r*c);
for dd = 1:d
    layer = I(:,:,dd);
    V(dd,:) = layer(:);
end
end

我不确定外部产品,但其他的都在这里

I1 = reshape(1:70*50*3, 70,50,3);
I2 = 0.4*reshape(1:70*50*3, 70,50,3);

i1 = reshape(I1, [], 3);
i2 = reshape(I2, [], 3);

我不确定外部产品,但其他的都在这里

I1 = reshape(1:70*50*3, 70,50,3);
I2 = 0.4*reshape(1:70*50*3, 70,50,3);

i1 = reshape(I1, [], 3);
i2 = reshape(I2, [], 3);