New to MatLab: Having some trouble

  • Thread starter Yosty22
  • Start date
  • Tags
    Matlab
In summary, the person is trying to read data from a text file into MatLab and graph it by fitting it with exponentials. They are using the code "%s%s" to read in the data as strings, but are getting an error when trying to run it. They have checked various sources and their code appears to be correct, but they realized they forgot to include ".txt" at the end of the filename.
  • #1
Yosty22
185
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
  • #2
Nevermind, sorry.. Apparently I forgot to type ".txt" at the end..
 

1. What is MatLab and what is it used for?

MatLab is a programming language and interactive environment commonly used for numerical computing and data analysis. It allows users to perform a variety of tasks such as creating algorithms, visualizing data, and developing models.

2. I am new to MatLab. How can I get started?

To get started with MatLab, you can refer to online tutorials and resources provided by MathWorks, the company behind MatLab. They offer free online courses, documentation, and support to help beginners learn the basics of the language and its applications.

3. I am having trouble understanding MatLab's syntax. What can I do?

MatLab's syntax may seem daunting at first, but with practice, it can become more intuitive. Start by familiarizing yourself with the basic syntax rules and conventions, and then try working through simple examples and exercises. You can also refer to the built-in help and documentation for guidance.

4. How can I troubleshoot errors in my MatLab code?

If you encounter errors while running your MatLab code, it is important to carefully read the error message to identify the source of the issue. You can also use the debugging tools provided by MatLab, such as the "debug" mode or the "dbstop" function, to step through your code and identify the problem.

5. Can I use MatLab for data analysis and visualization?

Yes, MatLab is widely used for data analysis and visualization. It offers a variety of tools and functions for importing, manipulating, and visualizing data. You can also use MatLab's powerful graphics capabilities to create visualizations such as plots, charts, and graphs to better understand your data.

Similar threads

  • Programming and Computer Science
Replies
4
Views
742
  • Engineering and Comp Sci Homework Help
Replies
3
Views
806
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
944
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
13
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
16
Views
1K
Back
Top