Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Importing 2 .txt files within the one import command

2 vues (au cours des 30 derniers jours)
bugatti79
bugatti79 le 16 Oct 2013
Clôturé : MATLAB Answer Bot le 20 Août 2021
Hi Folks,
How do I import 2 different .txt files containing numbers using the one import command as a function. Here is my code, it only imports the 2nd txt file for some reason.
function importfile(fileToRead1)
%IMPORTFILE(FILETOREAD1)
% Imports data from the specified file
% FILETOREAD1: file to read
% Auto-generated by MATLAB on 16-Oct-2013 20:59:38
DELIMITER = '\t';
HEADERLINES = 5;
% Import the file
Test = importdata('Name1.txt', DELIMITER, HEADERLINES);
% Create new variables in the base workspace from those fields.
vars = fieldnames(Test);
for i = 1:length(vars)
assignin('base', vars{i}, Test.(vars{i}));
end
DELIMITER = '\t';
HEADERLINES = 5;
% Import the file
Test2 = importdata('Name2.txt', DELIMITER, HEADERLINES);
%Create new variables in the base workspace from those fields.
vars = fieldnames(Test2);
for i = 1:length(vars)
assignin('base', vars{i}, Test2.(vars{i}));
end
end
Also I would like to have a unique name for each imported matrix. Thanks in advanced. B

Réponses (0)

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by