Not enough input arguments. And there is an error in "N = length(N_func);"
3 次查看(过去 30 天)
显示 更早的评论
Here is my code in editor:
function [ck , ck_magnitude, ck_phase] = analysis (N_func)
%%this is the analysis function
%N_func refers to the values for a function in a period
%ck refers to array of coefficients
%ck_magnitude refers to the arrays of coefficient magnitude
%ck_phase refers to the arrays of coefficient phase
%the goal is to create an array for fourier coefficient by using analysis
%equation
ck=zeros(0);
ck_magnitude=zeros(0);
ck_phase=zeros(0);
N = length(N_func);
for k = (0:N-1)
n = 0:N-1;
ck= [ck, (sum(N_func .*exp(-(1j)*2*pi*k*n/N)/N))];
ck_magnitude=[ck_magnitude, sqrt(real(ck(k+1))^2+img(ck(k+1))^2)];
ck_phase = [ck_phase, atan(imag(ck(k+1))/real(ck(k+1)))];
end
tiledlayout (2,1)
nexttile
plot_func('k' , 'phase(rad)', 0:N-1 , circshift(ck_phase,-1),'phase');
nexttile
plot_func('k', 'magnitude',0:N-1, circshift(ck_magnitude, -1),'magnitude');
end
2 个评论
Matt J
2022-1-26
You need to post it in a form that we can run as you did, i.e., we need to see how the function was invoked.
Also, we need to see complete copy/pastes of the error messages that you see.
回答(1 个)
Walter Roberson
2022-1-26
You cannot run that code just by clicking on the green Run button. You need to go down to the command line and invoke the code passing in a vector of data. (Or you could write a script that gathered the data and passed it to the function, and then you could press the green Run button on that script.)
4 个评论
Walter Roberson
2022-1-27
N_func = YourNFunction(appropriate_input_for_function);
[ck , ck_magnitude, ck_phase] = analysis(N_func);
where YourNFunction is the function that calculates N_func given appropriate parameters.
... If I were to guess about what you are actually trying to do:
dinfo = dir('*.xlsx');
filenames = fullfile( {dinfo.folder}, {dinfo.name});
nfiles = length(filenames);
cks = cell(nfiles,1);
ck_magnitudes = cell(nfiles,1);
ck_phases = cell(nfiles,1);
for K = 1 : nfiles
thisfile = filenames{K};
T = readtable(thisfile);
N_func = T{:,2}; %guessing about which column contains the data to be analyzed
[cks{K}, ck_magnitudes{K},ck_phases{K}] = analysis(N_func);
end
But I could easily be wrong. Perhaps instead you have a single signal and you have (somehow) split it into intervals, such as if you did silence detection.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Switches and Breakers 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!