MATLAB: Append columns from a known variable into cell

cell arraysMATLABxlswrite

Hi!
I can't seem to find the solution to this problem.
In my program I'm extracting data from multiple e.g. 6 excel files (through readcell), all with the same structure: column 1 with the quantity, column 2 with the value and column 3 with the unit of measurement, obtaining a {28,3} cell.
I then extract in a for loop the second column, and create a matrix of all the numeric values adding column after column for the different examines files.
What i'd like to do now is to create a cell with:
  • column 1 from the first cell with the quantity names;
  • column 2:(6+1) with the different values of the quantity across the 6 files
  • column 8 with the units of measurement;
Here is the script that I tried:
clear all
dataset=uigetfile('*.xlsx','Multiselect','on');
for i=1:length(dataset)
tri=readcell((dataset{1,i}));
estrai(:,i)=cell2mat(tri(:,2));
end
output=[tri(:,1),estrai];
xlswrite('Analysis',output)
If I run the script i get the following error:
Dimensions of arrays being concatenated are not consistent. Consider converting input arrays to the same type before concatenating.
I also tried writing output as output={tri(:,1),estrai} but instead of a 28×7 cell it returns a 1×2 cell, in which element {1,1} is a 28×1 cell and {1,2} is a 28×6 double. xlswrite('Analysis',output) in this case returns an empty excel file.
Any help?

Best Answer

Have you tested this? You are trying to join a cell array and a numerical matrix from what it seems.
output = [cell2mat(tri(:,1)),estrai]