New to MatLab: Having some trouble

  • Thread starter Thread starter Yosty22
  • Start date Start date
  • Tags Tags
    Matlab
Click For Summary
The user is new to MATLAB and is attempting to read data from a text file for research purposes but encounters an error related to the file identifier. They are using the textscan function with the format '%s%s' to read a file containing numerical data in scientific notation. The error message indicates an invalid file identifier, which is typically caused by an incorrect file path or name. The user later realizes that they forgot to include the ".txt" extension in the filename, which resolved the issue. This highlights the importance of ensuring correct file naming conventions when working with MATLAB.
Yosty22
Messages
182
Reaction score
4

Homework Statement



This isn't really for homework, but I wasn't sure where else to put it. anyone wishes to move it, that is fine. I'm just getting into some research and I was tasked with reading data from a text file into MatLab and then graphing it by fitting it with exponentials. I am very new to MatLab, so I am just trying to read the data in as of right now, and I'm not sure what's going wrong. I have used many sources online and I have done almost exactly what they said.

My code right now is as follows:

filename = 'aucdstio2_long_ave_combined';
fileID = fopen(filename,'r');
temp = textscan(fileID, '%s%s');

I am using the part '%s%s' because the file is formatted as:
-1.0000000e+003 1.5354302e+002

This is an example of the first line, but there are around 500 lines that are all identical to this. I figured due to the "e+003" it would be better to read it in as a string. However, when I try to run it, I keep getting the error: "

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

Error in Data_ReadIn_aucdstio2_long_ave_combined (line 5)
temp = textscan(fileID, '%s%s');

It is weird to me, because this is exactly what various sites I have found have said.

Any ideas what's going on here?

Homework Equations


N/A

The Attempt at a Solution



My attempt is shown above
 
Physics news on Phys.org
Nevermind, sorry.. Apparently I forgot to type ".txt" at the end..
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
7
Views
3K
Replies
2
Views
1K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K