for loop problem using variable
1 次查看(过去 30 天)
显示 更早的评论
SADFA
1 个评论
Stephen23
2020-3-26
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)
回答(1 个)
Ankita Bansal
2018-6-25
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?
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!