Error using fread Invalid file identifier. Use fopen to generate a valid file identifier.

13 views (last 30 days)
hi im trying to create this code for one of my assesments and for some reason it kkeeps coming up with this message im pretty sure everything else is correct btu i cant find whats causing the errror mesage above.
my code and one of the files its meant to read from is included

Accepted Answer

Stephen23
Stephen23 on 5 Jun 2020
Edited: Stephen23 on 5 Jun 2020
The problem is that your code only uses the filename, but you need to also provide the filepath (otherwise how does MATLAB know where the file is saved?). The filepath is provided as the second output of uigetfile:
[F,P] = uigetfile();
Results1 = fullfile(P,F);
Important: you should fclose every file that you fopen, otherwise your code will just collect more and more handles to open files, which can eventually cause various problems (errors, unresponsive, etc.)
Tip: you should name your variable with something more descriptive, i.e. that actually reflects their content and type.
  1 Comment
Jordan Stocker
Jordan Stocker on 5 Jun 2020
Thanks that works great now
but the strip lines which are meant to remove the letters so that the data can go through the calculations dont work either any sugestions would help lots

Sign in to comment.

More Answers (1)

N___e
N___e on 5 Jun 2020
Strip command only strip a single character.
stripCharacter — Character to strip from input text
' ' (default) | character | string
Character to strip from input text, specified as a character or as a string that contains one character.
You can use the erase command,
It can match the string you want to erase.

Categories

Find more on Dates and Time in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!