Matlab fopen, is it possible to have a numeric file name?

前端 未结 1 597
情歌与酒
情歌与酒 2021-01-29 03:36

I have the following code:

ptol = [2, 4, 8, ...];

a = ptol(1)

fid = fopen( a,\'r\');

I need to open a file determined by which number is call

相关标签:
1条回答
  • 2021-01-29 04:31

    a is a number, I guess.

    Thus, you need to specify a string which corresponds to the file name. Does the file have any extension? num2str and strcat should do the magic.

    The code:

    fileName = strcat(num2str(a),'.ext');
    fid = fopen(fileName,'r');
    

    Notice that .ext has to be replace with the actual extension. If you are using .txt files, then replace with .txt.

    Also, check for the position of the file (you need to specify the exact path).

    0 讨论(0)
提交回复
热议问题