How can I take an integer like n=1:1:50 and get the output for each value?

6 次查看(过去 30 天)
I want to plot my output for each input and the input is from 1 to 50, but I am not sure why my code is not working.
n=1:50; %my range, I want to check for each n values
f=n*175*10^6; % want to get frequency for each n
c=(sin(n*pi*d))/(n*pi*d) %d,tr,T these are my fixed values
d1=(sin((n*pi*tr)/T))/((n*pi*tr)/T);
In=2*d*Ipp*c*d1;
E=(In*f*L)/(0.8*r); %I am not getting E for each n values

回答(2 个)

Walter Roberson
Walter Roberson 2021-10-30
d = rand() %since it was not defined
d = 0.0687
T = rand() %since it was not defined
T = 0.3380
tr = rand() %since it was not defined
tr = 0.7222
L = rand() %since it was not defined
L = 0.8296
r = rand() %since it was not defined
r = 0.7237
Ipp = randi(255); %since it was not defined
n=1:50; %my range, I want to check for each n values
f=n*175*10^6; % want to get frequency for each n
c=(sin(n*pi*d))./(n*pi*d) %d,tr,T these are my fixed values
c = 1×50
0.9923 0.9692 0.9316 0.8803 0.8169 0.7431 0.6608 0.5722 0.4797 0.3857 0.2925 0.2024 0.1175 0.0397 -0.0295 -0.0887 -0.1371 -0.1742 -0.1996 -0.2137 -0.2171 -0.2105 -0.1951 -0.1724 -0.1438 -0.1110 -0.0756 -0.0394 -0.0039 0.0293
d1=(sin((n*pi*tr)/T))./((n*pi*tr)/T);
In=2*d*Ipp*c.*d1;
E=(In.*f*L)/(0.8*r);
plot(n, E)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021-10-30
Without knowing the size of your variables and just presuming some variables to be scalar and others to be a vector, here is the corrected code that is based on the color operator (:) :
n=1:50; %my range, I want to check for each n values
f=n*175*10^6; % want to get frequency for each n
c=(sin(n(:).*pi*d))./(n(:).*pi*d) %d,tr,T these are my fixed values
d1=(sin((n(:).*pi*tr)./T))./((n(:)*pi*tr)./T);
In=2*d(:).*Ipp*c*d1;
E=(In*f(:).*L)./(0.8*r); %I am not getting E for each n values
Presumably, you have here d and L or r to be a vector with a certain length.

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by