[英]How should I copy a smaller 2d array to a big 2d array using matlab?
[英]MATLAB using 2D Array
我想使用2D數組存儲img1,img2以及img1和img2的比較vlaue的所有值,我想實現類似的算法:
% read in the images from a folder one by one:
somefolder = 'folder';
filelist = dir([somefolder '/*.jpg']);
s=numel(filelist);
C = cell(length(filelist), 1);
for k=1:s
C{k}=imread([somefolder filelist(k).name]);
end
%choose any of the two images to compare
for t=1:(s-1)
for r=(t+1):s
img1=C{r};
img2=C{t};
ssim_value[num][1]=img1; % first img
ssim_value[num][2]=img2; % second img
ssim_value[num][3]=mssim; % ssim value of these two images
end
end
因此,使用我使用的2D數組(ssim_value),初始化它的正確方法是什么以及如何實現保存要存儲的值的目的存在錯誤。
有人可以幫我嗎。 提前致謝。
我假設“ num”是您將提供的數字,例如5或類似的數字。 您不能像在Python中那樣在數組中混合類型。 另外,正如@Schorsch指出的那樣,您可以在Matlab中使用括號來索引數組。
您要形成的二維數組必須是二維單元數組。 例如:
a = {{"a",3},{"two",[1,2,3]};
在這種情況下,a {1,2} = 3,而a {2,1} =“ two”。
您可能事先不知道目錄中有多少個文件,因此可能無法預先初始化單元格數組。 無論如何,Matlab陣列僅出於性能原因而需要預先初始化,並且您可以在Matlab中輕松找到有關初始化陣列的信息。
鑒於此,我很確定您要實現的目標是:
%choose any of the two images to compare
ssim_value = {};
for t=1:(s-1)
for r=(t+1):s
img1=C{r};
img2=C{t};
ssim_value{num,1}=img1; % first img
ssim_value{num,2}=img2; % second img
ssim_value{num,3}=mssim; % ssim value of these two images
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.