Create text string vector

5 visualizaciones (últimos 30 días)
Stefanie Wiese
Stefanie Wiese el 5 de En. de 2012
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

Respuestas (1)

Wayne King
Wayne King el 5 de En. de 2012
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

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by