for loop problem using variable

1 visualización (últimos 30 días)
frankenberry
frankenberry el 25 de Jun. de 2018
Comentada: Stephen23 el 26 de Mzo. de 2020
SADFA
  1 comentario
Stephen23
Stephen23 el 26 de Mzo. de 2020
Original question from Google Cache:
"for loop problem using variable"
In the code below, the size of scaled_stim and ShpModNoise are [4 32000]. The first line of the code works correctly. Now I want to pass the values to a variable to hold the 4 std (i.e., one std for each row of data). Then I want to average the four stds and adjust the dB levels.
scaled_stim(i,:) = ShpdModNoise(i,:).*10^(-16/20); %this line works, scaled_stim and ShpdModNoise are 4 32000
for scaled_stim(i,:)
adj_scale(i) = 20*log10(std(scaled_stim(i,:))) %converts to dB and stores value in adj_scale
end
adj_out=mean(adj_scale); %takes the average of the 4 values
Questions: 1. why won't the for loop work, each value can output on its own when I enter 1,: or 2,: or 3,: or 4,: - then I get the means at -31.7829; -33.7393; -36.8493; and -39.0284 but when it's in the loop it won't work or store the values. 2. How do I apply adj_out to adjust the data? I write the data out to a sound file after this as follows:
modFreqsstr = num2str(modFreqs(i));
filenam = [pth 'SAM_Noise' modFreqsstr 'x_24.wav'];
audiowrite(filenam,scaled_stim(i,:)',Fs,'BitsPerSample',24)

Iniciar sesión para comentar.

Respuestas (1)

Ankita Bansal
Ankita Bansal el 25 de Jun. de 2018
Hi, you are making mistake in line: "for scaled_stim(i,:)"
You need to modify the code as
ShpdModNoise=randi(5,4,32000);
scaled_stim = ShpdModNoise.*10^(-16/20);
for i=1:4
adj_scale(i) = 20*log10(std(scaled_stim(i,:)));
end
adj_out=mean(adj_scale);
I didn't get your 2nd question. Where are you applying adj_out and which data do you want to adjust? Can you provide more information?

Community Treasure Hunt

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

Start Hunting!

Translated by