MATLAB: Importing Files and Creating Contours

  • MATLAB
  • Thread starter MathematicalPhysics
  • Start date
  • Tags
    files Matlab
In summary: It will give you the syntax and options for the contour function. You can also use the "surf" command to create a 3D plot of your data. In summary, to show the contours of your data in MATLAB, you can use the "contour" function or the "surf" command. You can also use the "help" function to learn more about the syntax and options for these commands.
  • #1
MathematicalPhysics
40
0
Hey! I am using c++ to simulate charges dissipating. I've written the output to a file in the form of a matrix, so in the file is just a matrix of numbers showing equipotentials etc.

I want to show the contours by using MATLAB. I'm not used to working in MATLAB but I tried! I clicked file --> import data, then pointed it to the output file from c++ (just a .txt file).

After clicking next a few times it appears to have imported the correct file.

Now what do I do? Reading textbooks, I gather its something like:

>contour(...)

Im really not sure about this! I hope I don't have to start learning MATLAB from the beginning just to work this out! The point of my project is to use c++ to work out the charge dissipation, which I've done but wouldn't it be nice to have some pictures?!

Thanks in advance,

Matt
 
Physics news on Phys.org
  • #2
MathematicalPhysics said:
Hey! I am using c++ to simulate charges dissipating. I've written the output to a file in the form of a matrix, so in the file is just a matrix of numbers showing equipotentials etc.

I want to show the contours by using MATLAB. I'm not used to working in MATLAB but I tried! I clicked file --> import data, then pointed it to the output file from c++ (just a .txt file).

After clicking next a few times it appears to have imported the correct file.

Now what do I do? Reading textbooks, I gather its something like:

>contour(...)

Im really not sure about this! I hope I don't have to start learning MATLAB from the beginning just to work this out! The point of my project is to use c++ to work out the charge dissipation, which I've done but wouldn't it be nice to have some pictures?!

Thanks in advance,

Matt

You can writte "help contour" on the command window.
 
  • #3


Hi Matt,

Great job on successfully importing your data into MATLAB! Now, to create the contours, you will need to use the "contour" function. The basic syntax for this function is:

contour(X,Y,Z)

where X and Y are the coordinates of the points where the contours will be drawn and Z is the matrix containing the data values. In your case, X and Y will be the indices of your matrix (i.e. 1, 2, 3, etc.) and Z will be the actual values in your matrix. So, your code might look something like this:

contour(1:size(matrix,1), 1:size(matrix,2), matrix)

This will create a contour plot using the data in your matrix. You can also add additional arguments to customize the appearance of the plot, such as specifying the number of contour lines or adding a colorbar.

I understand that learning a new language can be daunting, but with some practice and experimentation, you will be able to create the desired plots in no time. Good luck with your project!
 

1. How do I import files into MATLAB?

To import files into MATLAB, you can use the importdata function. This function reads data from a file and stores it in a MATLAB array. You can specify the file format and delimiter in the function's input arguments.

2. Can I import multiple files at once?

Yes, you can import multiple files at once using the importdata function. Simply specify the file names in a cell array as the input argument.

3. How do I create contour plots in MATLAB?

To create contour plots in MATLAB, you can use the contour or contourf functions. These functions take in a matrix of data and plot contours at different levels. You can customize the appearance of the plot by specifying various input arguments.

4. Can I customize the contour levels in a contour plot?

Yes, you can customize the contour levels in a contour plot by using the contour or contourf functions. These functions allow you to specify the levels at which you want to plot the contours, as well as the colors and labels for each level.

5. What file formats are supported for importing into MATLAB?

MATLAB supports various file formats for importing, including CSV, TXT, XLS, and MAT files. You can specify the format in the importdata function's input arguments, or use the appropriate function for the specific file type (e.g. xlsread for Excel files).

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
800
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
4K
  • Programming and Computer Science
Replies
20
Views
492
  • MATLAB, Maple, Mathematica, LaTeX
Replies
22
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
935
Back
Top