# Plotting with a for loop

788 views (last 30 days)

Show older comments

##### 0 Comments

### Accepted Answer

Star Strider
on 1 Oct 2014

You probably have the plot command inside your loop.

Guessing as to your code, but it is best to do something like this instead :

for k = 1:n

x(k) = k;

y(k) = sin(x(k));

end

figure(1)

plot(x, y)

##### 8 Comments

Star Strider
on 2 Oct 2014

SUCCESS!

You don’t need the loop:

T_i=25;

T_infinity=800;

h=20;

t=325;

rho=720;

k=.16;

c=1255;

alpha=k/(rho*c);

u=((h*sqrt(alpha*t))/k);

x=0:.001:.1;

v=((h*x)/k);

w=(x/(2*sqrt(alpha*t)));

v=((h*x)/k);

w=(x/(2*sqrt(alpha*t)));

T=(((erfc(w)-exp(v+u^2).*erfc(w+u))*(T_infinity-T_i))+T_i);

plot(x,T);shg

produces:

### More Answers (3)

Esther Maria Ribezzo
on 13 May 2020

I have the same problem!!

for i=1:length(asse_x);

MLSE=(norm(AI_concatenated-(S*(A_TOT(:,i))))).^2;

plot(asse_x(i),MLSE, '*')

hold on

end

##### 0 Comments

Moh'd Allouzi
on 13 Jun 2021

for k = 1:n

x(k) = k;

y(k) = sin(x(k));

end

figure(1)

plot(x, y)

##### 0 Comments

alaa sleem
on 4 Jan 2022

cp=1.2

ta=30

hhv=50000

tex=130

k=1

for lamda =(.8,.1,1.5)

A_F(k)=lamda*x*(32+3.76*28)/(n*12+m*1)

if lamda < 1

N_CO2= x*((2*lamda)-1)-(m/4);

n_CO= x*((2*lamda)-1)-(m/4);

n_h2o=m/2;

n_n2=(lamda*x*3.76);

Total=N_CO2+n_CO+n_n2+n_h2o;

Xi_co2(k)=N_CO2/Total;

Xi__CO(k)=n_CO/Total;

Xi_h2o(k)=n_h2o/Total;

Xi_N2(k)=n_n2/Total;

#______________________________________________lean_____________________________________________

else lamda >= 1

N_CO2= n;

n_O2= x*(lamda-1);

n_h2o=m/2;

n_n2=(lamda*x*3.76);

Total=N_CO2+n_O2+n_n2+n_h2o;

Xi_co2(k)=N_CO2/Total;

Xi_o2(k)=n_O2/Total;

Xi_h2o(k)=n_h2o/Total;

Xi_N2(k)=n_n2/Total;

end

t_f(k) = ta+(hhv/((1+lamda)*cp))

eta(k)= ((1+lamda)*cp*(t_f-tex))/hhv

lamd_list(k)=lamda

k=k+1

end

fig1 = figure(1);

ax1 = axes('Parent', fig1);

A_F_plot = plot(lamd_list, total_util);

%concentration

plot(lamd_list,Xi_co2)

hold.on

plot(lamd_list(:lenght(Xi_o2)),Xi_o2)

hold.on

plot(lamd_list(:lenght(Xi__CO)),Xi__CO)

hold.on

plot(lamd_list,Xi_h2o)

hold.on

plot(lamd_list,Xi_N2)

hold.off

%air fuel

plot(lamd_list,A_F)

%temp

plot(lamd_list,A_F)

##### 0 Comments

### See Also

### Categories

### Products

### Community Treasure Hunt

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

Start Hunting!