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!