Concatenating matrices unable to create a row jump

2 ビュー (過去 30 日間)
ENRIQUE RIVERO PERAL
ENRIQUE RIVERO PERAL 2023 年 5 月 28 日
回答済み: Walter Roberson 2023 年 5 月 28 日
Im trying to concatenate different matrices for a local otsu method segmentation but I cannot join the matrices for my subimages.This error is displayed: Dimensions of arrays being concatenated are not consistent.
Winex and winey is how many subwindows I need in the x and y axis, winsize is an input and determines how big the subwindows will be.
l = 0;
for i=1:winex
for o=1:winey
l = l + 1;
tigger{i, o} = img((l-1)*winsize+1:l*winsize, (i-1)*winsize+1:i*winsize);
end
l = 0;
end
cruzzi = [];
for i=1:winex
for o=1:winey
carrey = graythresh(tigger{i, o});
cruzzi{i} = [cruzzi imbinarize(tigger{i,o}, carrey)];
end
end
mmcd = winex-1;
while mmcd ~= 0
alfin = [cruzzi{mmcd+1}
cruzzi{mmcd}];
mmcd = mmcd - 2;
end

回答 (1 件)

Walter Roberson
Walter Roberson 2023 年 5 月 28 日
cruzzi = [];
Numeric array.
cruzzi{i} = [cruzzi imbinarize(tigger{i,o}, carrey)];
First cycle, cruzzi is the empty numeric array, and the [] operation works. You would be assigning to cell index 1 relative to the empty numeric cruzzi, but as a special case when the target is empty double then instead of MATLAB complaining about wrong data types, it will go ahead and convert cruzzi to a cell array. So after the assignment statement, cruzzi will stop being an empty numeric array and will start being a 1 x 1 cell array.
Then, second iteration, [cruzzi imbinarize(tigger{i,o}, carrey)] will be [] between (all of) a 1 x 1 cell and a numeric array. The result in cruzzi{1} would be the imbinarize() result from the first iteration, and in cruizzi{2} would be a 1 x 2 cell array...
You are either going to eventually get errors between concatenating between cells and doubles of different sizes, or else you are going to get cruzzi being a chain of (mostly) cell arrays that refer to each other.
If you want to append a numeric array to a cell array, then initialize the cell array as a cell and use
cruzzi{end+1} = imbinarize(tigger{i,o}, carrey);

製品


リリース

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by