Read Text file and then use the outputs in a loop

1 回表示 (過去 30 日間)
jack walker
jack walker 2016 年 8 月 29 日
編集済み: Stephen23 2016 年 8 月 29 日
Hi i am just learning Matlab , any direction help would be great
I have a text file that contains 1 column. In this column is file paths. Some thing like this
C:\Users\jwalkerack\Documents\MTLAB\A_file.txt
C:\Users\jwalkerack\Documents\MTLAB\B_file.txt
C:\Users\jwalkerack\Documents\MTLAB\C_file.txt
i want to load these file path strings into a list , that i can then input into a for loop and do something
So far i have this
fid = fopen('C:\Users\jwalkerack\Documents\Tiff_deminsions\In\To_Process.txt');
% Read all lines & collect in cell array
C = textscan(fid ,'%s')
Y = C{1};
Count = 0
for i=1:length(Y)
elm = Y(i);
display(elm)
display(Count)
end
When i display elm it does seem to print out the file path , but when i try and put it into the next step , it does not reconise it as being a string , is there way i can convert the elm variable to be a string/filename
thanks for your time
  1 件のコメント
KSSV
KSSV 2016 年 8 月 29 日
編集済み: KSSV 2016 年 8 月 29 日
but when i try and put it into the next step...this is not clear..what you tried to do exactly?

サインインしてコメントする。

回答 (1 件)

Stephen23
Stephen23 2016 年 8 月 29 日
編集済み: Stephen23 2016 年 8 月 29 日
Change the parentheses to curly brackets:
elm = Y{i};
And then learn about the difference between () and {} for cell arrays:

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by