Problem with code when create a matrix in Maltab

1 回表示 (過去 30 日間)
Le Duc Long
Le Duc Long 2020 年 6 月 17 日
コメント済み: KSSV 2020 年 6 月 17 日
Hi everybody,
I have an error with my code when i create a matrix in matlab. Can you see it and help me!
-----------------------------------------
lamda=0.2;M=5;T=50;
for i=1:M
for j=1:M
if i==j B(i,j)=exp(-lamda*T);
elseif i>j B(i,j)=0;
else B(i,j)=exp(-lamda*T)*(lamda*T)^(j-i)/factorial(j-i);
end
end
end
K=zeros(1,M)
A=[B;K]
-------------------------------------------
If i run program in fisrt time ---> ok. No when i change value of "M=5" to another value and run again, it will be appear error:
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
Error in VD (line 14)
B=[A;K]z
----------------------------------
When I restart again Matlab, it will be ok at the first time and then error will be repeat. Please help me. If you have a good ideal and show me how to creat this metrix, i will be so very happy.
Thanks so much!
  1 件のコメント
KSSV
KSSV 2020 年 6 月 17 日
Preacclocate B to zeros using:
B = zeros(M) ;

サインインしてコメントする。

採用された回答

Paresh yeole
Paresh yeole 2020 年 6 月 17 日
Clear the variables before starting.
You may write
clear all
in the beginning of your code
  1 件のコメント
Le Duc Long
Le Duc Long 2020 年 6 月 17 日
Thank Paresh yeole. Your way is exactly. Do you have anyway to create my matrix?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by