Info

此问题已关闭。 请重新打开它进行编辑或回答。

Importing 2 .txt files within the one import command

1 次查看(过去 30 天)
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

回答(0 个)

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by