Turn multiple columns into one column

조회 수: 1 (최근 30일)
Colton McGarraugh
Colton McGarraugh 2021년 10월 15일
댓글: Star Strider 2021년 10월 15일
I have a code set up to calculate frequency from 20 different time columns and print 20 different frequencies.
However, I need to turn all these columns into 1 column. The problem I am running into is that it calculates freq each for loop, and I have allFreq=freq(:) before the for loop ends. However, it just prints the 20th freq calculation, instead of 1-20 on top of each other. Is there anyway to make it to where each time freq is calculated, it is added below the previous freq in the allFreq column?
for r = 1:numberDataSets
DeltaT(r,1) = time(3,r) - time(2,r); % subtracts the third row by the second row to find delta time and stores it in an array for every data set
end
%% Determining the length
for z = 1:20
for az = 1:L
if time(az,z) > 0
ne(z,1) = az;
end
end
end
%% Solving for the frequencies
%allfrequency = zeros(numberDataSets,L);
for s = 1:numberDataSets
fhat = fft(Acceleration(:,s),ne(s,1)); % calculates the fft
PSD = 98.1 * (fhat.*conj(fhat)/ne); % Computes the power spectrum density (removes the imaginary values) magniture
freq = 1/(DeltaT(s,1)*ne(s,1))*(0:ne(s,1)); % computes the frequency
Le = 1:floor(ne(s,1)/2); % only selects the first 1/2 of the frequencies
indices = PSD >= 20; % find all frequencies with larger power
PSDClean = (PSD.*indices); % zero out all the other terms
fhat = indices.*fhat; % zero out small fourier coefficients in y
%for sa = 1:ne(s,1)
allfrequency = freq(:)';
%end
end

답변 (1개)

Star Strider
Star Strider 2021년 10월 15일
The code is a bit difficult to follow. I’m guessing here that you want to save the ‘allfrequency’ vectors.
allfrequency(s,:) = freq(:)';
could do what you want.
.
  댓글 수: 2
Colton McGarraugh
Colton McGarraugh 2021년 10월 15일
Hi Star Strider,
Unfortunately that just moves the 20th freq array it calculates into the second column of allFrequency, and makes the entire 1st column a bunch of 0s.
Star Strider
Star Strider 2021년 10월 15일
As I mentioned, this is difficult to follow, and I can’t run it because I don’t have the data.
The point is that ‘freq(:)'’ iis a row vector, so since ‘s’ begins at 1 and loops through all of them (apparently 20),
allfrequency(s,:) = freq(:)';
should produce a (20xN) matrix, where ‘N’ is the vector length of ‘freq’. The only zeros should be those inherent in the ‘freq’ vector. It is perfectly reasonable for ‘freq’ to have 0 (Hz, or rad/sec or other units) as the first element.
.

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

카테고리

Help CenterFile Exchange에서 Filter Analysis에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by