Concatenating matrices unable to create a row jump
4 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Walter Roberson
on 28 May 2023
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);
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!