Borrar filtros
Borrar filtros

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 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Sagar Damle
Sagar Damle el 18 de Jul. de 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)

Más respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by