Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Importing 2 .txt files within the one import command

2 Ansichten (letzte 30 Tage)
bugatti79
bugatti79 am 16 Okt. 2013
Geschlossen: MATLAB Answer Bot am 20 Aug. 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

Antworten (0)

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by