Error using vertcat Dimensions of arrays being concatenated are not consistent.
1 回表示 (過去 30 日間)
古いコメントを表示
Dear all,
I implement this function:
function [SP_Simulation]=get_survivalprobability(a,b,w,dt,m,k)
for i=1:k
for j=1:m
hzrd(i,j)=exp(a(i)+b*w(i,j)) ;
end
end
h1=hzrd(1,:) ;
SP1=(sum(exp(h1*-dt)))/m ;
for i=1:k-1
h=(hzrd(i,:)+hzrd(i+1,:)).*-dt;
SP_others(i)=sum(exp(h),2)./m ;
SP_Simulation=[SP1 ; SP_others];
end
end
when I try to use it for the following main code:
k=5;
m=3000;
b=0.01 ;
SP=repmat(0.98,k,1) ;
w=rand(k,m);
fun=@(a) (get_survivalprobability(a,b,w,dt,m,k)-SP);
% find f(a)=0 such that equation (4.6) holds, given
% an initial guess a0
a0=ones(1,k);
[a] = fsolve(fun,a0);
% find hazard rates with the new parameters a
for i=1:k
for j=1:m
h(i,j)=exp(a(i)+b*w(i,j))
end
end
it shows me the following error: Error using vertcat Error using vertcat Dimensions of arrays being concatenated are not consistent.
Could someone please help me??
Thank you in advance
Regards,
Martina
0 件のコメント
回答 (1 件)
darova
2019 年 9 月 11 日
MATLAB doesn't know if SP_others is column or row vector. By default - row
SP_others(i)=sum(exp(h),2)./m ;
Then you are trying to concantenate
SP_Simulation=[SP1 ; SP_others];
Also i recommend you to pre-allocate memory for matrices
hzrd = zeros(k,m);
SP_others = zeros(k-1,1); % COLUMN
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!