Storing output values from a for loop into an “array”
Hello everyone,
I am trying to output the values that I get from a for loop into an "array". I am not sure how to store those "list of values" into an array
I have attached my code in reference:
Storing_Values_Into_Array.m
close all; clc;
% Value of j
j = 1i;
% For the region k_o < k_p < sqrt(u_r*e_r)*k_o
% Wavenumber in free space value = k_o
k = 2*pi;
% Permeability Value = u_r
u_r = 1;
% Permittivity Value e_r
e_r = 2.2;
% Value of kz_1
kz_1 = @(kp) sqrt((k).^2*e_r*u_r – (kp).^2);
% Value of kz_2
kz_2 = @(kp) sqrt((kp).^2 – (k).^2);
% Substrate heights = d
D = [0.02 0.04 0.06 0.08 0.10];
% Using a for loop to calculate the roots for T_M
% Solving for k_p values
for i=1:numel(D)
d=D(i);
% Equations for TM(kp)
T_M = @(kp) kz_1(kp).*sin(d.*kz_1(kp)) – e_r*kz_2(kp).*cos(d.*kz_1(kp));
kp_root=[fzero(T_M, [k , k*sqrt(e_r*u_r)])]
fplot(T_M,[k k*sqrt(e_r*u_r)], ‘LineWidth’,3); hold on
plot(kp_root,0,’o’,’MarkerSize’,8,’MarkerFaceColor’,’k’);
ylim([-5 5]);
xlim([k k*sqrt(e_r*u_r)]);
title(‘T_M vs k_p’)
ylabel(‘T_M’)
xlabel(‘k_p’)
grid on;
ax = gca;
ax.GridLineWidth = 2;
end; hold off
%{
What I am trying to do is store the values I get from "kp_root" in an
array called "kp_list" so I can use that array for calculations later on.
%}Hello everyone,
I am trying to output the values that I get from a for loop into an "array". I am not sure how to store those "list of values" into an array
I have attached my code in reference:
Storing_Values_Into_Array.m
close all; clc;
% Value of j
j = 1i;
% For the region k_o < k_p < sqrt(u_r*e_r)*k_o
% Wavenumber in free space value = k_o
k = 2*pi;
% Permeability Value = u_r
u_r = 1;
% Permittivity Value e_r
e_r = 2.2;
% Value of kz_1
kz_1 = @(kp) sqrt((k).^2*e_r*u_r – (kp).^2);
% Value of kz_2
kz_2 = @(kp) sqrt((kp).^2 – (k).^2);
% Substrate heights = d
D = [0.02 0.04 0.06 0.08 0.10];
% Using a for loop to calculate the roots for T_M
% Solving for k_p values
for i=1:numel(D)
d=D(i);
% Equations for TM(kp)
T_M = @(kp) kz_1(kp).*sin(d.*kz_1(kp)) – e_r*kz_2(kp).*cos(d.*kz_1(kp));
kp_root=[fzero(T_M, [k , k*sqrt(e_r*u_r)])]
fplot(T_M,[k k*sqrt(e_r*u_r)], ‘LineWidth’,3); hold on
plot(kp_root,0,’o’,’MarkerSize’,8,’MarkerFaceColor’,’k’);
ylim([-5 5]);
xlim([k k*sqrt(e_r*u_r)]);
title(‘T_M vs k_p’)
ylabel(‘T_M’)
xlabel(‘k_p’)
grid on;
ax = gca;
ax.GridLineWidth = 2;
end; hold off
%{
What I am trying to do is store the values I get from "kp_root" in an
array called "kp_list" so I can use that array for calculations later on.
%} Hello everyone,
I am trying to output the values that I get from a for loop into an "array". I am not sure how to store those "list of values" into an array
I have attached my code in reference:
Storing_Values_Into_Array.m
close all; clc;
% Value of j
j = 1i;
% For the region k_o < k_p < sqrt(u_r*e_r)*k_o
% Wavenumber in free space value = k_o
k = 2*pi;
% Permeability Value = u_r
u_r = 1;
% Permittivity Value e_r
e_r = 2.2;
% Value of kz_1
kz_1 = @(kp) sqrt((k).^2*e_r*u_r – (kp).^2);
% Value of kz_2
kz_2 = @(kp) sqrt((kp).^2 – (k).^2);
% Substrate heights = d
D = [0.02 0.04 0.06 0.08 0.10];
% Using a for loop to calculate the roots for T_M
% Solving for k_p values
for i=1:numel(D)
d=D(i);
% Equations for TM(kp)
T_M = @(kp) kz_1(kp).*sin(d.*kz_1(kp)) – e_r*kz_2(kp).*cos(d.*kz_1(kp));
kp_root=[fzero(T_M, [k , k*sqrt(e_r*u_r)])]
fplot(T_M,[k k*sqrt(e_r*u_r)], ‘LineWidth’,3); hold on
plot(kp_root,0,’o’,’MarkerSize’,8,’MarkerFaceColor’,’k’);
ylim([-5 5]);
xlim([k k*sqrt(e_r*u_r)]);
title(‘T_M vs k_p’)
ylabel(‘T_M’)
xlabel(‘k_p’)
grid on;
ax = gca;
ax.GridLineWidth = 2;
end; hold off
%{
What I am trying to do is store the values I get from "kp_root" in an
array called "kp_list" so I can use that array for calculations later on.
%} array, arrays, for loop MATLAB Answers — New Questions