Close a specific text file, while leaving different text files open (MatLab R2011b)

16 次查看(过去 30 天)
I am trying to close 1 of 4 open text files (leaving the other 3 open). I referred to the website above 'fclose'. When I try and close the file using: fclose(myfileid) the following error is shown "Error using fclose String argument must be 'all'"
fclose('all') works for closing ALL files but I NEED to keep the other 3 files open. Is this because I am working with an other version of MatLab? (R2011b) If so is there a workaround?
>> x = 'Cycle_HS1.txt'
x =
Cycle_HS1.txt
>> fopen(x)
ans =
3
>> fclose(x) Error using fclose String argument must be 'all'.
>> fclose('all')
ans =
0

采纳的回答

Michael Jarboe
Michael Jarboe 2015-12-23
编辑:Michael Jarboe 2015-12-23
Figured it out!
this works
% code below
end
x = 'Cycle_HS1.txt'
y = fopen(x)
(MatLab returns) y = 3
fclose(y)
(MatLab returns) ans = 0 (file is closed)
end
  2 个评论
Steven Lord
Steven Lord 2018-2-3
Call fopen with two outputs. When the first output is -1, read the message in the second output for more information about why MATLAB was unable to open the file.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by