Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Importing 2 .txt files within the one import command

2 visualizzazioni (ultimi 30 giorni)
bugatti79
bugatti79 il 16 Ott 2013
Chiuso: MATLAB Answer Bot il 20 Ago 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

Risposte (0)

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by