I am trying to write few arrays of equal size 1x234 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 1x234 cell. How to fix this?

 Akzeptierte Antwort

Image Analyst
Image Analyst am 11 Nov. 2016

0 Stimmen

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.

Weitere Antworten (1)

Guillaume
Guillaume am 11 Nov. 2016

1 Stimme

Even simpler,
t = table(Random, MeanVA, MeanC, MeanP, MeanI, MeanU , 'VariableNames', ...
{'RandomVariable', 'Meanof_VA_iter', 'Mean_of_C_iter', 'Mean_of_P_iter', 'Mean_of_I_iter', 'Mean_of_U_iter'});
writetable(t, 'Means.xlsx');

Community Treasure Hunt

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

Start Hunting!

Translated by