Effacer les filtres
Effacer les filtres

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

16 vues (au cours des 30 derniers jours)
Patrice Gaofei
Patrice Gaofei le 21 Nov 2017
Modifié(e) : Stephen23 le 21 Nov 2017
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.

Réponses (2)

KSSV
KSSV le 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 commentaire
Patrice Gaofei
Patrice Gaofei le 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

Connectez-vous pour commenter.


Roger Stafford
Roger Stafford le 21 Nov 2017
Modifié(e) : Roger Stafford le 21 Nov 2017
You should use the 'cat' function. It will allow you to concatenate along the fourth dimension.
  3 commentaires
Stephen23
Stephen23 le 21 Nov 2017
Modifié(e) : Stephen23 le 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 le 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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by