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
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 个评论
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 Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!