New to MatLab: Having some trouble

  • Thread starter Thread starter Yosty22
  • Start date Start date
  • Tags Tags
    Matlab
Click For Summary
SUMMARY

The discussion revolves around a user's difficulty in reading data from a text file into MATLAB for graphing purposes. The user attempted to use the textscan function with the format specifier %s%s to read a file named aucdstio2_long_ave_combined, but encountered an "Invalid file identifier" error. The issue was resolved when the user realized they had forgotten to include the ".txt" extension in the filename, which is essential for the fopen function to locate the file correctly.

PREREQUISITES
  • Basic understanding of MATLAB syntax and functions
  • Familiarity with file I/O operations in MATLAB
  • Knowledge of data formatting, specifically scientific notation
  • Experience with error handling in programming
NEXT STEPS
  • Learn about MATLAB's fopen function and its parameters
  • Explore the textscan function and its format specifiers
  • Research how to handle file errors in MATLAB
  • Investigate data visualization techniques in MATLAB, particularly fitting data with exponential functions
USEFUL FOR

This discussion is beneficial for beginners in MATLAB, particularly those involved in data analysis and visualization, as well as anyone encountering file reading issues in their programming tasks.

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