How to copy each column to other file faster?

2 visualizaciones (últimos 30 días)
adhi dermawan
adhi dermawan el 28 de Nov. de 2022
Comentada: adhi dermawan el 29 de Nov. de 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 comentarios
Jan
Jan el 28 de Nov. de 2022
Editada: Jan el 28 de Nov. de 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 el 28 de Nov. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Arif Hoq
Arif Hoq el 29 de Nov. de 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 comentarios
Arif Hoq
Arif Hoq el 29 de Nov. de 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 el 29 de Nov. de 2022
thank you kind sir

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Import from MATLAB en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by