Plotting values from a function in different script
13 ビュー (過去 30 日間)
古いコメントを表示
function [xvals,yvals]=fourier(L,nmax,numpoints)
xvals=[];
yvals=[];
for x=1:numpoints
y=0;
for n=1:2:nmax
y=y+(1/n)*(sin((n*pi*x)/L));
end
y=4*y/pi;
xvals=[xvals;x];
yvals=[yvals;y];
end
end
====================================================
[xvals,yvals]=fourier(L,nmax,numpoints);
x = xvals;
y = yvals;
L= 0;
plot(x, y);
I have a function that returns two very long column vectors for xvals and yvals. I'm struggling to create another script that calls upon this function and plots the respective xvals vs yvals. The code below the line gives me an error saying L is not recognized but I don't use it so I'm a bit confused.
0 件のコメント
採用された回答
KSSV
2022 年 2 月 11 日
編集済み: KSSV
2022 年 2 月 11 日
You have to define the required input variables first and then call the function.
L = 1. ;
nmax = 100 ;
numpoints = 1000 ;
[x,y]=fourier(L,nmax,numpoints);
plot(x,y);
function [xvals,yvals]=fourier(L,nmax,numpoints)
xvals=zeros(numpoints,1) ;
yvals=zeros(numpoints,1) ;
for i=1:numpoints
y=0;
for n=1:2:nmax
y=y+(1/n)*(sin((n*pi*i)/L));
end
y=4*y/pi;
yvals(i) = y ;
xvals(i) = i ;
end
end
3 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!