How to plot text file in MATLAB

In summary, the speaker had to use a network analyzer to measure a standing wave pattern along a transmission line. They took data points at half mm increments and got the values in a text file using software. However, they are having trouble formatting the axes for a plot. After some trial and error, they were able to successfully plot the data using the code provided.
  • #1
A.J.710
53
1
I had to use a network analyzer measuring the standing wave pattern along a transmission line taking data points at half mm increments. The software I used got me the values in a text file and the way it is formatted, I can't figure out how to make the left side the X axis and right side the Y axis of a plot. There are hundreds of points so I can't reorganize all of them manually. Below is an example of the first few lines of the text file.

%
-6.639705882353E+1 4.612014117183E-1
-6.637867647059E+1 4.611021652616E-1
-6.636029411765E+1 4.611021652616E-1
-6.634191176471E+1 4.608038003887E-1
-6.632352941176E+1 4.608038003887E-1

Thanks for the help
 
Physics news on Phys.org
  • #2
Never mind, I figured it out, I'll put the code below for anyone else to reference.

load file.txt;
x = file(:,1);
y = file(:,2);
plot(x,y);
 

1. How do I import a text file into MATLAB for plotting?

To import a text file into MATLAB, you can use the importdata function. This function will read the data from the text file and store it in a structure array. You can then use this array to plot your data.

2. What is the syntax for plotting a text file in MATLAB?

The syntax for plotting a text file in MATLAB depends on the type of plot you want to create. Generally, you will need to specify the data to be plotted and any additional parameters such as labels, colors, and styles. For example, to create a basic line plot, you can use the plot function and specify the data as follows: plot(x, y), where x and y are the vectors containing the data points.

3. How can I customize the appearance of my plot?

To customize the appearance of your plot, you can use various MATLAB functions such as xlabel, ylabel, title, and legend to add labels and titles. You can also use the set function to change properties such as line color, style, and marker. Additionally, you can use the subplot function to create multiple plots in a single figure.

4. Can I plot multiple text files in one figure?

Yes, you can plot multiple text files in one figure by using the hold on command. This command allows you to plot multiple data sets on the same axes. Simply use the plot function for each data set and then use hold off to turn off the hold function when you are finished plotting.

5. How can I save my plot as an image or PDF file?

To save your plot as an image or PDF file, you can use the saveas function. This function allows you to specify the file format and name for your saved plot. Alternatively, you can use the print function to save your plot directly to a file. Simply specify the file name, file format, and any other desired options.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Back
Top