How to write data in an excel sheet with one separate column for each iteration in a for loop?

조회 수: 3 (최근 30일)
I have a matlab script that has a for loop for 50 iterations. For each iteration the output is a 4097x1 matrix. I want to write each iteration in a separate sequential column so that at the end I have a 4097x50 matrix in the same excel sheet.
Please note that in the script the output is also getting as one row for all the iterations (that means 204850 rows (4097x50=204850)). If I can get all the results in a matrix form 4097x50 in matlab that also will do the purpose.
Can anyone please help me on this??
Thank You.........!!!!

채택된 답변

Image Analyst
Image Analyst 2014년 11월 24일
output = zeros(4097, 50); % Preallocate
for iteration = 1 : 50
output(:, iteration) = GetColumnVector(); % Stuff your 4097 elements into one column.
end
xlswrite(filename, output, 'A1');
  댓글 수: 2
Tharindu
Tharindu 2014년 11월 24일
편집: Image Analyst 2014년 11월 24일
Many thanks for your prompt response. I am little bit confused how to in-cooperate it into my script. Can you please help me how should I include this into following script. I am sorry I am relatively new to Matlab coding;
a=xlsread('V02_All_column5.xlsx');
b=xlsread('V02_All_column6.xlsx');
H1 = zeros( 4097, 1, 50 );
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(:,:,i)=Pfx(:,:)./Pff(:,:);
H2(:,:)=Pxx(:,:)./Pxf(:,:);
end
I want to get the output real(H1) in a separate column for each iteration.
Many thanks again.

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

추가 답변 (1개)

Tharindu
Tharindu 2014년 11월 24일
I got the desired output by adjusting like this; output = zeros(4097, 50); % Preallocate
for i = 1 : 50 output(:, i) =real(H1(:,1,i)); % Stuff your 4097 elements into one column. end xlswrite('1.xlsx', output, 'A')
Many thanks for your comments. It really helped.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by