フィルターのクリア

Matlab is not plotting anything

1 回表示 (過去 30 日間)
Mohammed
Mohammed 2013 年 3 月 6 日
Hi I'm working on a hw problem and I got the correct answers but the matlab is not plotting anything here is my code
for N = (5:5:85)
r = 0.15;
l = 50000;
p = [r * l * (1 + r/12)^(12 .* N )/ (12 * ((1+r/12)^(12 .* N) - 1 ))];
x = [N(1): N(end)];
y = [p(1) : p(end)];
disp( [ N p]);
plot(N,p)
format bank
end

回答 (2 件)

Chad Greene
Chad Greene 2013 年 3 月 6 日
編集済み: Chad Greene 2013 年 3 月 6 日
Matlab is plotting something--only the last value in the loop. To get the results with a loop, I suggest this solution:
N = (5:5:85);
p = NaN(size(N)); % preallocate to speed things up
for n = 1:length(N)
r = 0.15;
l = 50000;
p(n) = [r * l * (1 + r/12)^(12 .* N(n) )/ (12 * ((1+r/12)^(12 .* N(n)) - 1 ))];
% x = [N(1): N(end)];
% y = [p(1) : p(end)];
% disp( [ N p]);
format bank
end
plot(N,p)
However, I think the loop is unnecessary (loops tend to slow things down). I'd prefer this simpler solution instead:
N = (5:5:85);
r = 0.15;
l = 50000;
p = r * l * (1 + r/12).^(12 .* N )./ (12 * ((1+r/12).^(12 .* N) - 1 ));
plot(N,p,'r')

vijayasinthujan vijayaratnam
vijayasinthujan vijayaratnam 2013 年 3 月 6 日
clear all clc
N = (5:5:85);
r = 0.15;
l = 5000;
p = [r * l * (1 + r/12).^(12 .* N )./ (12 * ((1+r./12).^(12 .* N) - 1 ))];
x = [N(1): N(end)]; y = [p(1) : p(end)]; disp( [ N, p]) plot(N,p) format bank

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by