Clear Filters
Clear Filters

how can i concatenate or merge two variables in 4-D with different sizes

16 views (last 30 days)
i am preparing my input dataset for the trainNetwork function in matlab. after extracting two different parts of an initial image, i have put each part into different patches. the first group of patches is of size 32*32*1*13 the second group of patches is of size 32*32*1*9 i have tried to concatenate the two arrays of data into one table made up of the two groups of patches but it gave me the following error. i have tried both horizontal and vertical concatenation *Error using vertcat Dimensions of matrices being concatenated are not consistent. *Error using horzcat Dimensions of matrices being concatenated are not consistent.
please, how could i solve this problem? thanks very much for your contributions.

Answers (2)

KSSV
KSSV on 21 Nov 2017
I1 = rand(32,32,1,13) ;
I2 = rand(32,32,1,9) ;
I12 = zeros(32,32,1,13+9) ;
I12(:,:,1,1:13) = I1 ;
I12(:,:,1,14:end) = I2 ;
Or you may use squeeze to reduce one dimension and then try to merge.
  1 Comment
Patrice Gaofei
Patrice Gaofei on 21 Nov 2017
thank you very much for your response but i do not really understand how to use this method which you just proposed my two data sets are huge. this are their properties Name Size Bytes Class Attributes
one_person_nodules2 32x32x1x9 73728 double
Name Size Bytes Class Attributes
one_person_nodules1 32x32x1x13 106496 double

Sign in to comment.


Roger Stafford
Roger Stafford on 21 Nov 2017
Edited: Roger Stafford on 21 Nov 2017
You should use the 'cat' function. It will allow you to concatenate along the fourth dimension.
  3 Comments
Stephen23
Stephen23 on 21 Nov 2017
Edited: Stephen23 on 21 Nov 2017
"i have tried but it did not work. it kept showing the same error"
Roger Stafford's method will work perfectly for the array sizes that you have shown, concatenating along the fourth dimension as stated. Here is an example showing that concatenation along the fourth dimension works without error:
>> one_person_nodules2 = rand(32,32,1,9);
>> one_person_nodules1 = rand(32,32,1,13);
>> out = cat(4,one_person_nodules2,one_person_nodules1);
>>
Either you tried something else (you did not show us what you tried, so we have no idea what you are doing or why it did not work), or the array sizes that you gave in the comment above are incorrect.
Patrice Gaofei
Patrice Gaofei on 21 Nov 2017
thank you very much. i have been able to concatenate the two data sets
i am very grateful to everyone for their respective contributions

Sign in to comment.

Categories

Find more on Creating and Concatenating Matrices 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!