Don't understand the error with the lnods.

1 回表示 (過去 30 日間)
Harman Johal
Harman Johal 2023 年 11 月 15 日
コメント済み: Walter Roberson 2023 年 11 月 27 日
  3 件のコメント
Harman Johal
Harman Johal 2023 年 11 月 15 日
Oh sorry.
Walter Roberson
Walter Roberson 2023 年 11 月 15 日
Your coord is empty for some reason

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

回答 (1 件)

Rishi
Rishi 2023 年 11 月 27 日
Hi Harman,
I understand you want to know why you are getting this error. This can be overcome by changing the code in line 30 to:
lnods = fscanf(fid, '\n%d %d %d %f %f %f', [7,nelem]);
Earlier, the code did not scan through all of the values, so the next time you used the ‘fscanf’ function in line 51, no values were read.
You can learn more about the ‘fscanf’ function from the below documentation:
Hope this helps.
  1 件のコメント
Walter Roberson
Walter Roberson 2023 年 11 月 27 日
No, you need
lnods = fscanf(fid, '\n%d %d %d %f %d %f', [6,nelem]);
However it is better not to mix %d and %f in a single fscanf() call, as that ends up having to convert datatypes because all of the data is returned as a single vector. It would be better to use
lnods = fscanf(fid, '\n%f %f %f %f %f %f', [6,nelem]);
A %d format stops parsing at non-digits -- including stopping at decimal points or at exponential notation. The numbers %d can handle are the range -2147483648 to 2147483647 (for larger range you need %ld.) That range is easily handled by %f and %f will not stop reading if it encounters a decimal point or exponential notation.

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

カテゴリ

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