フィルターのクリア

How do I store values from a function in an array within a for loop?

2 ビュー (過去 30 日間)
Nicole Mezher
Nicole Mezher 2020 年 2 月 25 日
コメント済み: Guillaume 2020 年 2 月 25 日
for i=119:0.1:125
Shift_Vm= GHK(Nai,Ki,Cli,i,Ko,Clo,P_RestNa,P_RestK,P_RestCl);
x(i)=Shift_Vm
end
plot(x)
I am getting the error:Array indices must be positive integers or logical values.
Error in Nicole_HW2 (line 31)
x(i)=Shift_Vm
How do I store each value of Shift_Vm to an array so I can plot it

採用された回答

Guillaume
Guillaume 2020 年 2 月 25 日
something = 119:0.1:125; %give this variable a better name, a name that actually describes what the variable contain
x = zeros(size(something)); %preallocate the output for efficiency
for i = 1:numel(something)
x(i) = GHK(Nai,Ki,Cli,something(i),Ko,Clo,P_RestNa,P_RestK,P_RestCl);
end
  2 件のコメント
Nicole Mezher
Nicole Mezher 2020 年 2 月 25 日
Thank you, it worked. One quick thing, How can I plot my results as the steps being the x axis and the values from the function being the y axis. I tried it but I keep getting the wrong graph as a result
Guillaume
Guillaume 2020 年 2 月 25 日
plot(something, x);
Naming the result something else than x may make more sense.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by