How to have the data for each iteration for a for loop?

1 visualización (últimos 30 días)
Tharindu
Tharindu el 19 de Nov. de 2014
Comentada: Tharindu el 21 de Nov. de 2014
Hi I have two sets of acceleration excel sheets data (8192x50 each) and I need to perform Fast Fourier Transformation for the total set of columns taking the same column from each file. As I have 50 columns I have to do this for 50 times. I used the for loop but it will only give the results for the last iteration. please help me to get the whole set of data.
here is the script I used for the calculation;
a=xlsread('V02_All_column5.xlsx');
b=xlsread('V02_All_column6.xlsx')
for i =1:50
z=a(:,i);
x=b(:,i);
Fs=3200;
L=length(z);
NFFT=2^nextpow2(L);
window=hann(L/2);
noverlap=8;
[Pff(:,:),f]=pwelch(z(:,:),window,noverlap,NFFT,Fs);
[Pxx(:,:),f]=pwelch(x(:,:),window,noverlap,NFFT,Fs);
[Pfx(:,:),f]=cpsd(z(:,:),x(:,:),window,noverlap,NFFT,Fs);
[Pxf(:,:),f]=cpsd(x(:,:),z(:,:),window,noverlap,NFFT,Fs);
H1(:,:)=Pfx(:,:)./Pff(:,:);
H2(:,:)=Pxx(:,:)./Pxf(:,:);
end
I want to get the H1 values for the whole iteration. Please help me.
Thank You .........!!!

Respuesta aceptada

per isakson
per isakson el 19 de Nov. de 2014
Editada: per isakson el 20 de Nov. de 2014
Replace
H1(:,:)
by
H1(:,:,i)
and initialize H1 before the loop.
&nbsp
Addendum
"initialize" is short for Preallocating Memory
Add this line before the loop
H1 = zeros( n1, n2, 50 );
choose n1 and n2 so that H1 gets its final size
  3 comentarios
per isakson
per isakson el 20 de Nov. de 2014
I added a couple of lines to the answer.
Tharindu
Tharindu el 21 de Nov. de 2014
Hi many thanks for your kind assistance.
I think it is working now. But don't know how to see the data. Because in the command window it only shows some values of the H1. When I try to export it MS excel using xlswrite('1.xlswrite',real(H1));
it returns the error message 'Dimension of input array cannot be higher than two.'
Can you explain me how to write it to an excel sheet. Please note that for each iteration H1 should have 4097 measurements. I would love if I can have the results in a 4097x50 matrix rather than having all the iteration results in the same column.
Many thanks again.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by