Nested for loop produces plot that is shifted horizontally

1 回表示 (過去 30 日間)
positron96
positron96 2018 年 5 月 27 日
コメント済み: positron96 2018 年 5 月 27 日
Hi, I want to set up a nested for loop to plot mRNA expression levels (y) over time (t) for different values of beta. y = 10 * beta (1 - exp(-t/10)).
time = [0 : 0.5 : 10];
beta = transpose([1 : 5]);
y = zeros(5, 21); % initializing a matrix of zeros to store y values
for time_point = 1 : length(time)
for beta_val = beta
y(beta_val, time_point) = 10 * beta .* (1 - exp(-1/10 .* (time_point)));
end
plot(time, y);
end
With this, I successfully get a plot, but it seems like the plot is shifted. y has to be zero for all plots at t=0.
Can someone tell me what I am doing wrong?

採用された回答

sloppydisk
sloppydisk 2018 年 5 月 27 日
編集済み: sloppydisk 2018 年 5 月 27 日
You evaluated at the index of the timevector, rather than at the time itself. You could write time(time_point) instead to get the desired result. Or you could make just evaluate on a grid and avoid the loop altogether:
time = 0:0.5:10;
beta = (1:5)';
y = 10 * beta * (1 - exp(-.1*time));
plot(time, y);

その他の回答 (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