clear
clc
eta = 100;
a= 0;
xi=0.016;
axis([0 0.01 0 1.1]);
x = 0:0.0001:0.01;
N = -a+1.6*(1/(xi*eta));
y=N;
plot(x,y,'LineWidth',2);
set(gca,'FontSize',10);Hi. I'd like to plot the function $N(x)$ (indeed, constant), on MATLAB, but the code above does not return any line on window. Why? Many thanks!
$\endgroup$ 13 Answers
$\begingroup$I like to write it
y=N+0*x;Matlab automatically creates the array with the correct length. And, since you are multiplying it by 0, you create essencially a constant vector.
$\endgroup$ 1 $\begingroup$If you wanted to create an array of ones then you could do
y=ones(size(x));or write
clear;
clc;
eta = 100;
a= 0;
xi=0.016;
axis([0 0.01 0 1.1]);
x = 0:0.0001:0.01;
temp = ones(size(x));
N = temp.*(-a+1.6*(1/(xi*eta)));
y=N;
plot(x,y,'LineWidth',2);
set(gca,'FontSize',10);Though, it is extremely unclear why you are writing
N = -a+1.6*(1/(xi*eta));when you could just write
N = 1;or just make an array of ones and write
clear;
clc;
eta = 100;
a= 0;
xi=0.016;
axis([0 0.01 0 1.1]);
x = 0:0.0001:0.01;
y = ones(size(x));
plot(x,y,'LineWidth',2);
set(gca,'FontSize',10); $\endgroup$ 1 $\begingroup$ Y and X should be the same size: y = N*size(x)
$\endgroup$ 3