フィルターのクリア

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

16 ビュー (過去 30 日間)
Patrice Gaofei
Patrice Gaofei 2017 年 11 月 21 日
編集済み: Stephen23 2017 年 11 月 21 日
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.

回答 (2 件)

KSSV
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.
  1 件のコメント
Patrice Gaofei
Patrice Gaofei 2017 年 11 月 21 日
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

サインインしてコメントする。


Roger Stafford
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
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.
Patrice Gaofei
Patrice Gaofei 2017 年 11 月 21 日
thank you very much. i have been able to concatenate the two data sets
i am very grateful to everyone for their respective contributions

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by