No values in plot?
2 views (last 30 days)
Show older comments
Here's the following code I've written to make a plot that is equal to the inverse of mathematical constant e (e). I can't quite figure out why my plot is completely empty when I open it, so I'm thinking I'm missing something somewhere. Any suggestions on what I need to do to get the right plot?
clear;
counter=1;
for i=1:50
My_numb_1=i;
My_numb_2=abs(1./My_numb_1);
My_numb_3=abs(1-My_numb_2);
My_numb_4=abs(My_numb_3.^i);
end
% plot of error vs n
x=counter;
y=My_numb_4;
plot(x,y)
grid on;
title('error vs. n');
xlabel('n');
ylabel('error');
0 Comments
Answers (1)
David Hill
on 24 Sep 2020
Not sure what you were doing, but each loop iteration you were overriding your data. No loop needed.
My_numb_1=1:50;
My_numb_2=1./My_numb_1;
My_numb_3=1-My_numb_2;
My_numb_4=My_numb_3.^My_numb_1;
plot(My_numb_1,My_numb_4);
grid on;
title('error vs. n');
xlabel('n');
ylabel('error');
0 Comments
See Also
Categories
Find more on Digital Filter Analysis in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!