필터 지우기
필터 지우기

arrange file length matlab

조회 수: 1 (최근 30일)
sam aldoss
sam aldoss 2018년 10월 17일
댓글: sam aldoss 2018년 10월 17일
hello everyone
I got some files that has a length 20000 cell and the others are shorter then 20000 . I want to make these short files to complete the set of cell 20000 with replacing the missing with ones or zeros .
and am using this code to read the files
for k = 1:numfiles
myfilenames = sprintf('a%d.wav', k);
[mydata{k}, myfs{k}] = audioread(myfilenames,[1,2000]);
end
  댓글 수: 1
Jan
Jan 2018년 10월 17일
What is the purpose of "[1, 2'000]"? You mention "20'000" also. Is this a typo? What does "cell" mean? Remember that cell is a specific type of array in Matlab. Replacing with "ones or zeros" - please decide this by your own. What does "make these files to complete" mean? Do you want to create files with a standard length or does the question concern the arrays in Matlab only?

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

채택된 답변

Jan
Jan 2018년 10월 17일
편집: Jan 2018년 10월 17일
Maybe:
for k = 1:numfiles
File = sprintf('a%d.wav', k);
[signal, myfs{k}] = audioread(File);
if size(signal, 1) < 20000 % Pad signal with zeros
signal(20000, :) = 0;
end
mydata{k} = signal;
end
Usually "data" is a sufficient name already, while "mydata" is a tiny overkill - of course these are your data ;-) Especially "myfilenames" is confusing to specify one file.
  댓글 수: 1
sam aldoss
sam aldoss 2018년 10월 17일
thanks man you really save me

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

추가 답변 (1개)

KSSV
KSSV 2018년 10월 17일
A{1} = rand(50,1) ;
A{2} = rand(40,1) ;
A{3} = rand(60,1) ;
L = max(cellfun(@length,A)) ; % get maximum length
iwant = cell(size(A)) ;
for i = 1:length(A)
iwant {i} = zeros(L,1) ;
iwant{i}(1:length(A{i})) = A{i};
end
  댓글 수: 4
Jan
Jan 2018년 10월 17일
@sam aldoss: "does not work" is a weak description of the occurring problem. Please share all information you have to make it as easy as possible to help you. The need to guess the details is not useful. Thanks.
Jan
Jan 2018년 10월 17일
@KSSV: cellfun('length', C) is more efficient than cellfun(@length, C).

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

카테고리

Help CenterFile Exchange에서 Signal Generation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by