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?

 채택된 답변

Image Analyst
Image Analyst 2016년 11월 11일

0 개 추천

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.

추가 답변 (1개)

Guillaume
Guillaume 2016년 11월 11일

1 개 추천

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');

카테고리

질문:

2016년 11월 11일

댓글:

2016년 11월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by