Reading all columns and rows of a matrix in a for loop
조회 수: 7 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
Sulaymon Eshkabilov
2021년 10월 18일
Your code should work correctly according to your described statements and variable sizes.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!