How can I reshape and resize an array?

조회 수: 2 (최근 30일)
Hanuman Crawford
Hanuman Crawford 2017년 7월 24일
댓글: Hanuman Crawford 2017년 7월 24일
I am trying to divide a signal (audio file) into frames with a length of 128.
I'm using the reshape() function but the problem is that the number of samples cannot be divided by 128 so I am getting an error "To RESHAPE the number of elements must not change.".
The solution I thought of is to increase the number of elements in the array to the next multiple of 128 before using the reshape() function. So far I have written code for calculating the number of elements I should extend the array by (copy/pasted below). I am looking for a way to extend the array by the calculated number of elements.
It feels like this should be a pretty simple task but I am fairly new to Matlab so I don't yet know the syntax.
[x,fs] = audioread('audio.wav');
windowLength = 128;
frames = length(x)/windowLength;
frames = ceil(frames);
extend = windowLength*frames - length(x);

채택된 답변

Walter Roberson
Walter Roberson 2017년 7월 24일
If you have the Signal Processing Toolbox, use buffer()
  댓글 수: 1
Hanuman Crawford
Hanuman Crawford 2017년 7월 24일
Thanks! I just tried this and it worked perfectly.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by