Help concatinating in for loop

3 views (last 30 days)
Flyers28
Flyers28 on 13 Sep 2019
Commented: darova on 13 Sep 2019
I can not seem to figure out something that should be so intuitve. I need to store the values of x end to end for each pass of the first for loop. So when r=2 it stores the values of x right after the values of x when r=1. This will create a large 1x44100 vector which I will then use to plot and generate a sound clip. Some code didn't get copied ie Ar and Ac are from the size command. The other varaibles are already defined from a loaded file so don't sweat that. The reason I am creating a vector instead of an areay is because the soundsc command only likes vectors.
x=0; %initializ x to 0
numWin = [1: (0.05*fs)]; %generates array for #samples/window 1:2205
for r = 1:Ar %Sets The row or Window to be calculated
t=numWin ./ fs; %converts sample/window to sec/window
for c = 1:Ac %Sets the column for each frequency to be calc
xt = 2 * abs(A(r,c)) * cos(2*pi* freqs(r,c)* t + angle(A(r,c)));
x = x + xt; % Sums together each xt to generate sum for all values of xt
end
numWin = numWin + length(numWin); %increments to next time window
tnew(r,:)=t; %stores time for each window into an array for each pass through loop
end

Answers (1)

Flyers28
Flyers28 on 13 Sep 2019
Edited: Flyers28 on 13 Sep 2019
I think I figured it out... albeit probably the worst way possible. But it worked. in the first floop I just did xnew(1,(r*blahblah - blah):(r*blahblah)) = x.
Still open to what the experts have to say though.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!