Array indices must be positive integers or logical values.

hey, im new in matlab.
I have attached the original question and my solution is written below:
clc; clear;
%t = linspace(0,2,100);
t= (0:0.05:2);
V=12;
R=4;
L=1.3;
g= zeros(1,length(t));
for j=t
if j<=0.5
g(j)=((V\R)*(1-(exp((-R*j)\L))));
else
g(j)=(exp((-R*j)\L)*(V\R)*(exp((0.5*R)\L)-1));
end
end

回答 (1 件)

KSSV
KSSV 2019 年 5 月 3 日
編集済み: KSSV 2019 年 5 月 3 日

1 投票

Note that the index of array cannot be zero, negative and fraction...so the error.
%t = linspace(0,2,100);
t= (0:0.05:2);
V=12;
R=4;
L=1.3;
g= zeros(1,length(t));
for j=1:length(t)
if t(j)<=0.5
g(j)=((V\R)*(1-(exp((-R*j)\L))));
else
g(j)=(exp((-R*j)\L)*(V\R)*(exp((0.5*R)\L)-1));
end
end

2 件のコメント

yoav raytz
yoav raytz 2019 年 5 月 3 日
Thank you for your answer,
can you show me how i can rewrite the code and make it work?
KSSV
KSSV 2019 年 5 月 4 日
I gave you the code right?

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

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

質問済み:

2019 年 5 月 3 日

コメント済み:

2019 年 5 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by