Merging Cell Array Elements with cellstr
조회 수: 2(최근 30일)
I want to merge the elements of the cell array of 100x4. After this merge, it will become 100x1. To do this process, I am using
temp = string(reshape(cell_temp, , 4));
merged= cellstr(temp(:,1) + temp(:,2) + temp(:,3) + temp(:,4))
Are there any other methods to merge them in shorter way? Because sometimes I want to merge 15 elements but I don't want to write them explicitly. Thank you.
Abhijit Nayak 2022년 6월 9일
I understand you want to automate merging of columns for a given matrix by using ‘cellstr’ function. The following code would work for any number of columns.
Create an array and assign it to ‘cell_temp’ variable in the code.
cell_temp = ones(100,5);
merged=merged + temp(:,i);