how can i concatenate or merge two variables in 4-D with different sizes
16 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (2 件)
KSSV
2017 年 11 月 21 日
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.
Roger Stafford
2017 年 11 月 21 日
編集済み: Roger Stafford
2017 年 11 月 21 日
You should use the 'cat' function. It will allow you to concatenate along the fourth dimension.
3 件のコメント
Stephen23
2017 年 11 月 21 日
編集済み: Stephen23
2017 年 11 月 21 日
"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.
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!