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
Jerin Joseph Koshy
Jerin Joseph Koshy 2018년 2월 3일
x = 'Cycle_HS1.txt'; y = fopen(x) i am getting y=-1????? can u pls tell me the reason??????
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