fopen function in MATLAB

5 ビュー (過去 30 日間)
Sushant
Sushant 2022 年 11 月 24 日
回答済み: Sivapriya Srinivasan 2023 年 3 月 2 日
I am trying to open an ABAQUS input file via "fopen" function in MATLAB, but i am unable to open it.
  5 件のコメント
Sushant
Sushant 2022 年 11 月 29 日
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 2022 年 11 月 29 日
@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);

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

回答 (1 件)

Sivapriya Srinivasan
Sivapriya Srinivasan 2023 年 3 月 2 日
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.

カテゴリ

Help Center および File ExchangeLow-Level File I/O についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by