Create text string vector

조회 수: 4 (최근 30일)
Stefanie Wiese
Stefanie Wiese 2012년 1월 5일
I would like to creat a text string vector to import data into Matlab, looking like:
A=['C:\Data\file1.txt'
C:\Data\file2.txt'
C:\Data\file3.txt'
C:\Data\file4.txt'
C:\Data\file5.txt'
C:\Data\file6.txt'
C:\Data\file7.txt']
What I tried to do does not really work out:
for i=1:7
eval(['A=['C:\Data\file' num2str(i) '.txt']']);
end
Would be great, if anybody could help me.
Thanks a lot

답변 (1개)

Wayne King
Wayne King 2012년 1월 5일
Hi Stefanie,
How about using a cell array.
A={'C:\Data\file1.txt',
'C:\Data\file2.txt',
'C:\Data\file3.txt',
'C:\Data\file4.txt',
'C:\Data\file5.txt',
'C:\Data\file6.txt',
'C:\Data\file7.txt'};
Then you can use A{1}, A{2}, and so on.
If you want to do it your way:
for nn = 1:5
test = ['c:\data\file' num2str(nn) '.txt'],
end

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by