필터 지우기
필터 지우기

How to copy each column to other file faster?

조회 수: 6 (최근 30일)
adhi dermawan
adhi dermawan 2022년 11월 28일
댓글: adhi dermawan 2022년 11월 29일
Dear matlab expert, I have 2 excel data . The first one is the main data, the other one is the output file. I want to copy each column of the main data to the third column of the output file one by one with the header still on and save it as txt format for each copy. How can copy each column and make a multiple output file all at once?
  댓글 수: 2
Jan
Jan 2022년 11월 28일
편집: Jan 2022년 11월 28일
Why there are 4 Excel files attached?
What have you tried so far? Which names do you want for the output files? Are you able to import the Excel files already? Then please post the existing code.
What does "faster" mean - faster than what?
adhi dermawan
adhi dermawan 2022년 11월 28일
Sorry sir, I already deleted those 2 files. I am able import the excel
clc;clear; close all;
format long g
filename1 = 'C:\ZTD\MainData.xlsx';
filename2 = 'C:\ZTD\Output.xlsx';
zw = readtable (filename2);
pwv = readmatrix(filename1);
I want to copy and paste the value in each column of the main data to the third column of the Output and save it as 01.txt,02.txt and so on with the same format as the output excel file. There are 1820 column in the Main Data so the result will be 1820 txt file.

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

채택된 답변

Arif Hoq
Arif Hoq 2022년 11월 29일
mainfile=readtable('MainData.xlsx');
outputfile=readtable('Output.xlsx');
C=cell(size(mainfile,2),1);
for i=1:size(mainfile,2)
outputfile(:,3)=mainfile(:,i);
result=[outputfile(:,[1 2]) outputfile(:,3) outputfile(:,4)];
C{i,1}=table2cell(result);
end
mat=[C{:}];
% making text files
for j=1:4:size(mat,2)
col= mat(:,j:j+3);
writecell(col,[num2str(j) '.txt'])
end
  댓글 수: 3
Arif Hoq
Arif Hoq 2022년 11월 29일
try this:
mainfile=readtable('MainData.xlsx');
outputfile=readtable('Output.xlsx');
C=cell(size(mainfile,2),1);
for i=1:size(mainfile,2)
outputfile(:,3)=mainfile(:,i);
result=[outputfile(:,[1 2]) outputfile(:,3) outputfile(:,4)];
C{i,1}=table2cell(result);
end
mat=[C{:}];
varname={'Lat','Lon','PWV','STA'};
repitvar=repmat(varname,1,size(mat,2)/4);
mat2=[repitvar;mat];
% making text files
for j=1:4:size(mat2,2)
col= mat2(:,j:j+3);
writecell(col,[num2str(j) '.txt'])
end
adhi dermawan
adhi dermawan 2022년 11월 29일
thank you kind sir

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by