Filter löschen
Filter löschen

How to copy each column to other file faster?

6 Ansichten (letzte 30 Tage)
adhi dermawan
adhi dermawan am 28 Nov. 2022
Kommentiert: adhi dermawan am 29 Nov. 2022
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 Kommentare
Jan
Jan am 28 Nov. 2022
Bearbeitet: Jan am 28 Nov. 2022
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 am 28 Nov. 2022
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Arif Hoq
Arif Hoq am 29 Nov. 2022
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 Kommentare
Arif Hoq
Arif Hoq am 29 Nov. 2022
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 am 29 Nov. 2022
thank you kind sir

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Import from MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by