Effacer les filtres
Effacer les filtres

How to copy each column to other file faster?

6 vues (au cours des 30 derniers jours)
adhi dermawan
adhi dermawan le 28 Nov 2022
Commenté : adhi dermawan le 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 commentaires
Jan
Jan le 28 Nov 2022
Modifié(e) : Jan le 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 le 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.

Connectez-vous pour commenter.

Réponse acceptée

Arif Hoq
Arif Hoq le 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 commentaires
Arif Hoq
Arif Hoq le 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 le 29 Nov 2022
thank you kind sir

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Import from MATLAB dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by