Excel export script help request
显示 更早的评论
Dear Matlab Users,
I have written code to create an export to excel file .m function. i believe it is correct code until----->
DataFinal = [date, name, Data]; where it has the error
Error using horzcat
CAT arguments dimensions are not consistent.
How do I solve this? What have I done incorrectly? How can I fix this? to get the excel file exported?
The code is below
Thank you
load djip1.mat
% list all individual stocks
aa = pricesMat(:,1);
axp = pricesMat(:,2);
% define length of name and date as N and T
N = length(name);
T = length(date);
%create company name series
tempname = cell(1, N);
for i = 1:N;
tempname = repmat(name,1);
end;
n = length(name); %no. of columns (no. of variables * no. of companies)
k = n/N; %no. of variables
Data = [];
for i = 1: N
tempdata = pricesMat;
Data = [Data; tempdata];
end;
DataFinal = [date, name, Data];
%ERROR appears here!!!!
%Export the organized data into excel files
TITLE = {'date','AA','AXP'};
xlswrite('dataFinal.xls',TITLE,'sheet3','A1')
xlswrite('dataFinal.xls',Name,'sheet3','A2');
xlswrite('dataFinal.xls',DataFinal,'sheet3','B2');
采纳的回答
更多回答(1 个)
Yash
2012-6-30
编辑:Walter Roberson
2012-7-1
see horzcat error come when you dont have the same number of rows in the variable you are concatenating horizontally so make sure they are same and separated by commas
like ill show a horzcat examples as
load XY.txt; % read data into the sector matrix
bigX=XY(:,2);
bigY=XY(:,1);
kstart=max(t1,t2)+1;
N=length(x)-kstart+1; %x
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%Find best FIT parameters for the series
for k=kstart:length(x)
p(k)=x(k-t1)/(1+x(k-t1)^c1);
p1(k)=x(k-1);
p2(k)=y(k-t2)/(1+y(k-t2)^c2);
p3(k)=y(k-1);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f=p(kstart:length(x));
f1=p1(kstart:length(x));
f2=p2(kstart:length(x));
f3=p3(kstart:length(x));
a=f'; % now transposing them becasue size of x is 519-1 and size of f was 1-519
a1=f1';
a2=f2';
a3=f3';
m=bigX(kstart:length(x));
bigX=horzcat(m,a,a,a2,a3);
类别
在 帮助中心 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!