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!