How to create for loop to find coefficients of segments?

2 views (last 30 days)
Hi all. I have a data matrix named: y (150x240)
I'm using each column (150 datas) of that matrix to find some parameters.
For example, for first frame:
y1=y(1:150)
p=10;
[a,g] = lpc(y1,p)
And same for second column(y2=y(151:300)) I need to find [a,g] for all columns. How can I create for loop for this?

Accepted Answer

Image Analyst
Image Analyst on 12 Apr 2016
Try this:
[rows, columns] = size(y);
p=10;
for col = 1 : columns
thisColumn = y(:, col);
[a(col), g(col)] = lpc(thisColumn, p);
end
  5 Comments
Image Analyst
Image Analyst on 12 Apr 2016
OK - it turns out that lpc is a function in the Signal Processing Toolbox. I don't use that function or know what it does. But if you have just [a,g] then you're overwriting a and g on every iteration so of course it will have only the values from the last iteration. That's why you need to index them. If g is a scalar and a is a 11 element array, you can do
[a(col, :), g(col)] = lpc(thisColumn, p);
Before the loop, preallocate a:
a = zeros(columns, 11);

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!