MATLAB: Error while using xlswrite for arrays

cell arrayserrorxlswrite

I am trying to write few arrays of equal size 1×234 into excel but getting the following error. "Dimensions of matrices being concatenated are not consistent." My code is as follows:
Mean_percentage=[{'RandomVariable','Meanof_VA_iter','Mean_of_C_iter','Mean_of_P_iter','Mean_of_I_iter','Mean_of_U_iter'};Random,MeanVA,MeanC,MeanP,MeanI,MeanU]
xlswrite('Means', Mean_percentage)
All the arrays Random, MeanVA,MeanC,MeanP,MeanI,MeanU are of size 1×234 cell. How to fix this?

Best Answer

The strings need to be in one cell each. And each element of each array needs to be in its own cell. Try it like this:
Mean_percentage ={'RandomVariable','Meanof_VA_iter','Mean_of_C_iter','Mean_of_P_iter';'Mean_of_I_iter','Mean_of_U_iter'};
for row = 1 : length(MeanVA)
Mean_percentage(row, 1) = {Random(row)};
Mean_percentage(row, 2) = {MeanVA(row)};
Mean_percentage(row, 3) = {MeanC(row)};
Mean_percentage(row, 4) = {MeanP(row)};
Mean_percentage(row, 5) = {MeanI(row)};
Mean_percentage(row, 6) = {MeanU(row)};
end
xlswrite('Means.xlsx', Mean_percentage)
Or you could use xlswrite a bunch of times (if you're using a later release of MATLAB). Use it once to write all the column headers, then once for each array, being sure to transpose the arrays into a column vector.