how can i concatenate or merge two variables in 4-D with different sizes
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponses (2)
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
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
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.
Voir également
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!