Turn multiple columns into one column

2 views (last 30 days)
Colton McGarraugh
Colton McGarraugh on 15 Oct 2021
Commented: Star Strider on 15 Oct 2021
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

Answers (1)

Star Strider
Star Strider on 15 Oct 2021
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 Comments
Star Strider
Star Strider on 15 Oct 2021
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.
.

Sign in to comment.

Tags

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by