fopen function in MATLAB

6 views (last 30 days)
Sushant
Sushant on 24 Nov 2022
I am trying to open an ABAQUS input file via "fopen" function in MATLAB, but i am unable to open it.
  5 Comments
Sushant
Sushant on 29 Nov 2022
I am pasting some lines of my code here, below.
fileID = fopen('new1.txt');
formatSpec = '%f';
N = 8;
% reads file data, using the formatSpec N times
% c_h: cell header
c_h = textscan(fileID,formatSpec,N,'delimiter','|')
% Read coordinates for nodes on the two opposite surfaces
% Save them in a cell array whose first and fourth columns are node #
% rest columns are x,y,z coordinates
% c_cord
c_cord = textscan(fileID,'%d %f %f %f %d %f %f %f')
fclose(fileID);
Jan
Jan on 29 Nov 2022
@Sushant: Whenever you try to open a file, check the success:
[fileID, msg] = fopen('new1.txt');
assert(fileID > 0, msg);
I guess, that using an absolute path solves the problem:
[fileID, msg] = fopen('C:\Path\To\WhereTheFileIs\new1.txt');
assert(fileID > 0, msg);

Sign in to comment.

Answers (1)

Sivapriya Srinivasan
Sivapriya Srinivasan on 2 Mar 2023
Hey Sushant,
Here are some possible solutions when you are unable to open an ABAQUS input file via fopen function in MATLAB
1.Check file format: ABAQUS input files are typically text files, but they may have a different file extension, such as ".inp". You can try opening the file with a text editor to check its format.
2.Check file encoding: ABAQUS input files are typically encoded in ASCII format. Make sure that the file is encoded in ASCII and not in some other encoding format.
3.Check the file path: Make sure that the file path you are providing to the fopen function is correct. If the file is not located in the current working directory, you will need to provide the full path to the file.
4.Check file permissions: Ensure that you have read permissions for the file. If the file is write-protected, you may not be able to open it.
5.Use the correct mode: Make sure that you are using the correct mode when opening the file. For example, if you want to read from the file, you should use the "r" mode. If you want to write to the file, you should use the "w" mode.
If none of these solutions work, you may need to provide more information about the error you are encountering.

Community Treasure Hunt

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

Start Hunting!