필터 지우기
필터 지우기

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 CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by