Help concatinating in for loop

조회 수: 3 (최근 30일)
Flyers28
Flyers28 2019년 9월 13일
댓글: darova 2019년 9월 13일
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

답변 (1개)

Flyers28
Flyers28 2019년 9월 13일
편집: Flyers28 2019년 9월 13일
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.
  댓글 수: 1
darova
darova 2019년 9월 13일
Maybe you forgot about X also?
1Capture.PNG

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by