Reading all columns and rows of a matrix in a for loop

2 views (last 30 days)
Maria Sarcos
Maria Sarcos on 18 Oct 2021
I have written the following code to calculate the power spectrum of a time series of wind speeds.
The u_hov_mat is a 6x12000 matrix and the Sf_mat is 12000x6. I have also made a variable for f_2 which is the same size as u_hov_mat and Sf_mat.
I am not quite sure if what I have written is correct and if the loop is going through each column and row and taking the corresponding values for the Sf_mat calculation. When I run the code it doesn't give me an error but the values I get inside the Sf_mat don't really make sense.
Is my code correct or do I need to change something?. Btw the code won't run because the values for u_hov_mat are inside a .csv file that I am reading in the beginning of the code.
N2=6;
dt2=10*60;
Sf_mat=zeros(size(u_hov_mat));
f2=linspace(f1_2,fs,72000);
f_2 = reshape(f2',[],N2);
for i=1:length(Sf_mat(1,:))
for j=1:length(Sf_mat(:,1))
Sf_mat(j,i) = (1/(2*pi*N2*f_2(j,i))) * (abs(fft(u_hov_mat(j,i)')))^2;
end
end

Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 18 Oct 2021
Your code should work correctly according to your described statements and variable sizes.

Community Treasure Hunt

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

Start Hunting!