Plotting with a for loop

60 Ansichten (letzte 30 Tage)
Jayme
Jayme am 1 Okt. 2014
Bearbeitet: Kay am 13 Aug. 2023
I have a for loop and need to plot my final results. I have the hold on command in my code, but I still get only one point on my plot. What am I doing wrong?

Akzeptierte Antwort

Star Strider
Star Strider am 1 Okt. 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 Kommentare
Jayme
Jayme am 2 Okt. 2014
When I use this method, I have a completely blank graph. Where as before, I could get a point.
Star Strider
Star Strider am 2 Okt. 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:

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (4)

Esther Maria Ribezzo
Esther Maria Ribezzo am 13 Mai 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

Moh'd Allouzi
Moh'd Allouzi am 13 Jun. 2021
for k = 1:n
x(k) = k;
y(k) = sin(x(k));
end
figure(1)
plot(x, y)

alaa sleem
alaa sleem am 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)

Kay
Kay am 13 Aug. 2023
Bearbeitet: Kay am 13 Aug. 2023
I can't seem to get this plot to work. It only pot a single point. How can I make it plot multiple points? I probably need a for loop but I don't know how to use it here. Thanks!
% Calculate PAE for a Time-Varying Complex Baseband Signal
Pdc = 10; % DC input power in watts
Gain_dB = 15; % Power amplifier gain in dB
% Convert gain from dB to linear scale
Gain = 10^(Gain_dB/10);
% Define the time vector and the baseband complex signal parameters
t = linspace(0, 1, 1000); % Time vector from 0 to 1 second
wc = 2*pi*10; % Carrier frequency in radians per second
% Define the time-varying envelope function (you can change this function as needed)
a_t = 1 + 0.5*sin(2*pi*5*t); % Amplitude envelope with variations over time
% Define the phase modulation function (you can change this function as needed)
phi_t = pi/4 * sin(2*pi*t); % Phase modulation with variations over time
% Generate the baseband complex signal x(t) = a(t) * exp(j*(wc*t + phi(t)))
x_t = a_t .* exp(1j*(wc*t + phi_t));
% Calculate the power of the baseband signal
P_baseband = sum(abs(x_t).^2) / length(x_t); % Average power of the signal
% Calculate the RF output power using the power amplifier gain
Pout = P_baseband * Gain;
% Calculate the Power Added Efficiency (PAE) using the formula: PAE = (Pout - Pdc) / Pdc * 100
PAE = (Pout - Pdc) / Pdc * 100;
% Display the PAE value
fprintf('Power Added Efficiency (PAE) = %.3f%%\n', PAE);
% Plot the PAE against the RF output power
figure(6)
plot(Pout, PAE, '-o','LineWidth', 2);
xlabel('RF Output Power (Pout) in Watts');
ylabel('Power Added Efficiency (PAE) in %');
title('PAE vs. Output Power for Time-Varying Complex Baseband Signal');
grid on;

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by