Hi !
I'm trying to import .txt files into matrixes.
I can import my -=C1.txt to -=C8.txt files one after another into matrixes (C1 to C8). See example below with matrix C8.What I want to do is making a for loop to import those 8 datas in 1 run. To do so, I need to change those numbers "/Users/.../-=C 8.txt" and "C 8 = cell2mat(raw);" for each increment (from 1 to 8). I tried sprint(), str2num() and many others without finding any solutions. PS: that code has been generated by the Import Wizard in Matlab.
filename = '/Users/.../-=C8.txt';
delimiter = '\t';
startRow = 3;
formatSpec = '%s%s%s%s%s%s%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'HeaderLines' ,startRow-1, 'ReturnOnError', false);
fclose(fileID);
%turn point into comma ... blablabla
C8 = cell2mat(raw);
clearvars filename delimiter startRow formatSpec fileID dataArray ans raw col numericData rawData row regexstr result numbers invalidThousandsSeparator thousandsRegExp me R;

 채택된 답변

Thorsten
Thorsten 2015년 10월 13일
편집: Thorsten 2015년 10월 13일

0 개 추천

i = 8;
filename = sprintf('/Users/.../-=C%d.txt', i)
or
filename = ['/Users/.../-=C' int2str(i) '.txt']
BTW '...' looks really strange to me as a directory name...

댓글 수: 1

Romain Marchant
Romain Marchant 2015년 10월 13일
int2str(i) works ! Thanks !
'...' was just for hiding the long directory name.
Do you know how I can store cell2mat(raw) in a new variable name at each incrementation ?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Standard File Formats에 대해 자세히 알아보기

질문:

2015년 10월 13일

댓글:

2015년 10월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by