plot the graph of function

3 次查看(过去 30 天)
l=633;
k0=2*pi/l;
ea=1.39;
da=1:300;
theta=1:70;
y=zeros(length(theta),length(da));
np=1.5;
x=(2*pi/l)*np*sind(theta);
for i=1:length(theta)
for j=1:length(da)
ka=k0*sqrt(ea-x.^2);
f=(1-exp(2*1i.*da(j).*ka(i)))/(1+exp(2*1i.*da(j).*ka(i)));
%pfms=2*atan(1i*a.*b);
y(i,j)=2*atan(1i*c.*f);
disp(y)
end
end
plot(da,y )
error message pl plot between da vs y and dy/da vs da
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-100.

采纳的回答

Kevin Hanekom
Kevin Hanekom 2022-1-29
clc;clear;close all;
l=633;
c = 1;
k0=2*pi/l;
ea=1.39;
da=1:300;
theta=1:70;
y=zeros(length(theta),length(da));
np=1.5;
x=(2*pi/l)*np*sind(theta);
for i=1:length(theta)
iter = 0;
for j=1:length(da)
iter
ka=k0*sqrt(ea-x.^2);
f=(1-exp(2*1i.*da(j).*ka(i)))/(1+exp(2*1i.*da(j).*ka(i)));
%pfms=2*atan(1i*a.*b);
y(i,j)=2*atan(1i*c.*f);
% disp(y);
iter = iter + 1;
end
end
plot(da,y )
What exactly is wrong?
  2 个评论
shiv gaur
shiv gaur 2022-1-29
编辑:Walter Roberson 2022-1-31
this program is working pl help one pl plot da vs dy/dda
why this is not working in function define
clc;clear;close all;
l=633;
c = 1;
k0=2*pi/l;
ea=1.39;
da=1:300;
theta=1:70;
y=zeros(length(theta),length(da));
np=1.5;
x=(2*pi/l)*np*sind(theta);
function y=f(theta,da)
for i=1:length(theta)
iter = 0;
for j=1:length(da)
iter
ka=k0*sqrt(ea-x.^2);
f=(1-exp(2*1i.*da(j).*ka(i)))/(1+exp(2*1i.*da(j).*ka(i)));
%pfms=2*atan(1i*a.*b);
y(i,j)=2*atan(1i*c.*f);
% disp(y);
iter = iter + 1;
plot(da,y )
end
end
end
your program in not working pl help
Walter Roberson
Walter Roberson 2022-1-31
That code never calls the function f
Reminder: your y is a 2D array that is changing in size as you go (since you do not pre-allocate). And each time you assign to a new y(i,j) location, you are plotting using the constant-sized vector da as the independent variable, and using all of the changing-size y as the dependent variable. That is going to run into size mismatches, and is also going to be attempting to plot locations in y that have not been explicitly given a value yet.
What is the point of doing the plot inside the double nested loop?
It might make sense to plot at the end of the double nested loop.
... but it would probably make more sense to return y to the calling function and let the calling function plot whatever it wants.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by