problem with fread,matrix arguments

4 ビュー (過去 30 日間)
panagiotis
panagiotis 2012 年 2 月 12 日
編集済み: Matt J 2013 年 10 月 9 日
i'll need some help here...well i have a folder who's inside there are 8 subfolders with names ('aa','ah','ax' 'eh' 'ih' 'ix' 'ow' 'ux')each subfolder has 60 .pcm files..and i want to read them..here's my code for phoneme 'aa'..the problem is when i write sig(k,i) as a matrix there's an error and i can't fix it..
%mycode
TrainFile=cd('C:\Users\panagiotis\Documents\MATLAB\patreco_project\training');
phonemes={'aa' 'ah' 'ax' 'eh' 'ih' 'ix' 'ow' 'ux' };
cd(phonemes{1});
data=dir('*.pcm');
for k=1:60
for i=1:length(data)
fid=fopen(data(i).name,'r');
sig(k,i)=fread(fid,inf,'int16'); %error
fclose(fid);
end
%note:each .pcm file has different length of data( the 1st pcm is 1x1298,the 2nd 1x890, etc..) namely for each phoneme i want to create a 2-dim matrix for each phoneme with 60 rows and different columns's length..
any help/ideas??
thx in advance

採用された回答

panagiotis
panagiotis 2012 年 2 月 12 日
error in line 2 i mean "CAN'T" not "CAN"
  3 件のコメント
panagiotis
panagiotis 2012 年 2 月 13 日
no,thx for noted it!
Jan
Jan 2012 年 2 月 19 日
Please accept the answer, which solves the problem.

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

その他の回答 (2 件)

Jan
Jan 2012 年 2 月 12 日
The command fread(fid,inf,'int16') replies a vector, but you try to assign it to the scalar sig(k,i). Please post a copy of the error message, whenever you mention the error in the forum.
Do all files contain the same number of elements? If not, you can use a cell, e.g. sig = cell(1, 60).
There are further problems in the code, e.g. you use the first phonemes only and the contents of sig(k, i) does not depend on k.

panagiotis
panagiotis 2012 年 2 月 12 日
yes i use the first phoneme in order to find the error and then i think its easy to generalise it ;)
I know my assignment error but i can still find the solution to this. Firstly i want to read the 60 .pcm files (each of .pcm has different size) from subfolder 'aa'(phoneme{1} in the code)
TrainFile=cd('C:\Users\panagiotis\Documents\MATLAB\patreco_project\training');
phonemes={'aa' 'ah' 'ax' 'eh' 'ih' 'ix' 'ow' 'ux' };
cd(phonemes{1});
data=dir('*.pcm');
for i=1:length(data)
fid=fopen(data(i).name,'r');
sig=fread(fid,inf,'int16');
fclose(fid);
end
can you fix this with cell command?? this for loop obviously is wrong cause only prints the last .pcm file from subfolder 'aa'.if you fix me for 'aa' then i can do it generally!
thx in advance!
  2 件のコメント
Walter Roberson
Walter Roberson 2012 年 2 月 12 日
replace sig with sig{i}
panagiotis
panagiotis 2012 年 2 月 13 日
first of all thx a lot,also if i want to generalise it for all 8 phonemes i'll create a second for loop for k=1:8
and the sig will be sig{k,i}! am i right ?? thx in advance!

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

カテゴリ

Help Center および File ExchangePCM についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by