Iterate values into array

Hi folks,
I have this data,
time = tbl.time;
Vv1 = tbl.Vv1;
Vv2 = tbl.Vv2;
IR6 = tbl.IR6;
f = [];
R = [];
Ratio = [];
L=[];
M=[];
for x = 3:height(Vv1)
G = tbl.Vv2(x)/tbl.IR6(x);
R(x) =[G];
Ratio = R(x);
end
xold=1
for i=1:length(Ratio);
xnew = ((xold-xold^2)*Ratio(i)) ;
L(i)=xnew;
M(i)=xold;
xold=xnew;
end
but for some reason each iteration of xnew and xold arent added to L or M ?

3 件のコメント

Adam Danz
Adam Danz 2020 年 11 月 2 日
If you provide tbl within a mat file it will be much easier to troubleshoot.
KSSV
KSSV 2020 年 11 月 2 日
xold=1
for i=1:length(Ratio);
xnew = ((xold-xold^2)*Ratio(i)) ;
The above line gives xnew as zero.....this what you want? You need to rethink on your logic.
for x = 3:height(Vv1)
G = tbl.Vv2(x)/tbl.IR6(x);
R(x) =[G];
Ratio = R(x);
end
The above lines, you need not to use loop.
Peter Perkins
Peter Perkins 2020 年 11 月 20 日
I don't think either of these loops is necessary. Edward, you should try to rewrite your code with vectorixed operations, it will be faster, shorter, easier to read, and easier to debug.

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

回答 (0 件)

カテゴリ

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

タグ

質問済み:

2020 年 11 月 2 日

コメント済み:

2020 年 11 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by