Adi is set to 0 when i = 1

1 回表示 (過去 30 日間)
isamh
isamh 2020 年 2 月 3 日
回答済み: isamh 2020 年 2 月 4 日
Adi = (Vd+1 - Vdi-1)/(2*(.1))
i have a equation that's plus and minus 1 from values within a column. column is made up of numbers from 0 all the way to 100.
how would i convert all i = 1 to 0?
my code is:
Vd = vdi.*(Vdi==1)==0;
Adi = ((Vd + 1)-(Vd - 1)/(2*(.1));
the entire column equals to 10, must be wrong.(noticed the entire column is equal to 1 and the equation equals to 10)

回答 (2 件)

Spencer Chen
Spencer Chen 2020 年 2 月 3 日
Not sure what you are trying to do with Adi. If you solve the mathematical formula:
Adi = ((Vd + 1)-(Vd - 1)/(2*(.1));
Adi = (Vd-Vd + 1+1)/(2*(.1));
Adi = (2)/(0.2);
Adi = 10;
So you'll get 10, no matter what.
Next, it is unclear what you mean by "convert all i = 1 to 0"? Because i is not defined.
I guess you mean convert all values in Vdi that is == 1 to 0.
You definitely did not do this correctly.
Now, you did good by finding those values in Vdi that is equal to 1:
(Vdi==1)
The problem that you had is in the assignment. You shoudl brush up on Matlab's indexing. But a hint:
Vdi(Vdi==1)
Will get you all the data in Vdi that is equal to 1.
By itself, it is not all that useful, because you know that the output of this will be all 1s. But think about what you can do with it to achieve the assignment operation that you want to do.
Blessings,
Spencer

isamh
isamh 2020 年 2 月 4 日
thanks for the response!
when Vd = Vdi_1.*(Vdi_1 == 1); it returns a row of all zeros and Adi is all 10s.

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by