フィルターのクリア

Argggh! My equation isn't plotting right with a for loop!!!

1 回表示 (過去 30 日間)
Jesse
Jesse 2015 年 3 月 27 日
コメント済み: Jesse 2015 年 3 月 27 日
Greetings all,
This is probably trivial and overlooking a minor detail, but I have the following code, and I think my problem is that I have to start at zero somewhere:
Response_values= 0:0.1:2;
phiv=zeros(size(Response_values));
for n=1:length(Response_values)
if Response_values(n)<2.1
phiv(n)=(4*n)/((4*n.^2+1).^3/2)
else
phiv(n)=0;
end
end
plot(Response_values,phiv);
As it is right now, "n" isn't being indexed right, therefore my plot is wrong. I know as of right now it starts at 1 and goes to 21. I wanted the equation to go from 0 to 2 in .1 increments. I know in MATLAB you can't start at an index of zero, so I searched these boards and tried to code the above.
Any help would be appreciated.
Thanks! -J

採用された回答

Image Analyst
Image Analyst 2015 年 3 月 27 日
Try this:
Response_values= 0:0.1:2;
phiv=zeros(size(Response_values));
for n=1:length(Response_values)
rValue = Response_values(n);
if rValue < 2.1
phiv(n)=(4*rValue)/((4*rValue.^2+1).^3/2)
else
phiv(n)=0;
end
end
plot(Response_values,phiv);
grid on;
xlabel('Response Value', 'FontSize', 20);
ylabel('phiv', 'FontSize', 20);
  1 件のコメント
Jesse
Jesse 2015 年 3 月 27 日
Yes! Thank you so much!!!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by