I want to be able to preallocate multiple iterations of a matrix inside a for loop i.e. matrix(cou​nt)=zeros(​L:1), matlab keeps telling me dimensions don't match. Is there a syntax way to do this? I was thinking maybe change to an if else if.....

1 回表示 (過去 30 日間)
if true
% code
end
Fs=2000;
nBits=8;
nChannel=1;
devID=1;
L=4000;
disp('press 1 for training dictionary')
result=input(':');
if result==1
count=input('number of refernce files to make(max number 5): ')
if count>5
disp('I told you not to go higher than 5!!!')
else
dictionmatrix1=zeros(L:1);<---I want to preallocate based on the count
dictionmatrix2=zeros(L:1);
dictionmatrix3=zeros(L:1);
dictionmatrix4=zeros(L:1);
dictionmatrix5=zeros(L:1);
end
for count=n:-1:1
ISAC=audiorecorder(Fs,nBits,nChannel,devID);
disp('Please makes sure to speak clearly and at the same distance from the microphone')
disp('for all reference samples. Recording in....')
for time=3:-1:0
x=time
pause(1);
disp(x);
end
disp('Start Recording');
recordblocking(ISAC,2);
disp('Processing');
testarray=getaudiodata(ISAC);
a=zeros(L:1);
a(1:L)=testarray(1:L);
dictionmatrix(count)=a;%<------I want to save to the preallocated matrix
end end
if true
% code
end

採用された回答

Sagar Damle
Sagar Damle 2014 年 7 月 18 日
If you want to create 5 vectors of the same size,instead of
count=5
for n=count:-1:1
dictionmatrix{n}=zeros(L:1)
end
you can use
dictionmatrix = zeros(L,1,count)
where you can refer to matrix3 as a whole by -
dictionmatrix(:,:,3).
If you want to refer 4th element of 2nd matrix,then use -
dictionmatrix(4,1,2)

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by