Effacer les filtres
Effacer les filtres

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.....

2 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Sagar Damle
Sagar Damle le 18 Juil 2014
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)

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by