What should I do to correct user defined function?

2 ビュー (過去 30 日間)
Explorer
Explorer 2016 年 3 月 14 日
編集済み: Explorer 2016 年 3 月 15 日
I have written code for function file i.e nsr_f.m
Getting following error when calling it:
Error using arburg (line 72)
The number of rows of X must at least 5.
Error in nsr_f (line 33)
[d1,p1,rc] = arburg(seg,4);
Error in feature_matching (line 3)
nsr_f(fs,Ekg,Gain)
Code to call function:
Gain = 200; fs=128;
d = load('PhysioNet_Database\NSR\16272m.mat'); Ekg = d.val(1,:);
nsr_f(fs,Ekg,Gain)
  2 件のコメント
Explorer
Explorer 2016 年 3 月 14 日
編集済み: Explorer 2016 年 3 月 14 日
MAT file also attached
Image Analyst
Image Analyst 2016 年 3 月 14 日
I'm pretty sure this is the route to solving it: Click me

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2016 年 3 月 14 日
You do not pre-initialize seg, so it is growing as you execute your loop. You start with i = 1 and assign something to seg(i,:) . That would assign to seg(1,:) the first time, so your seg is going to start out as a single row. You then pass that single row to arburg(), but arburg() requires at least 5 rows to work on, so it fails.
If you somehow succeeded on that first call, then you would go to the next iteration of the loop and would assign to seg(i,:) which would be seg(2,:) so you would be growing seg to two rows, and passing that to arburg(), which would then be processing not only this new row but the previous row. You would thus be incrementally refining your coefficients as you want through the entire EEG, first output based upon the first segment, second output based upon the first two segments, third output based upon the first three segments, and so on. Are you sure that is what you want?
I suspect you want to populate the seg matrix completely before calling arburg()
  1 件のコメント
Explorer
Explorer 2016 年 3 月 15 日
編集済み: Explorer 2016 年 3 月 15 日
I found the solution of my problem because of what your wrote above. Thank you!
I replaced following things:
% function [seg]=nsr_f(fs,Ekg,Gain) with
function [rc_seg]=nsr_f(fs,Ekg,Gain)
% and [d1,p1,rc] = arburg(seg,4) with
[d1,p1,rc] = arburg(seg(i,:),4);

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by