How to plot text file in MATLAB

Click For Summary
SUMMARY

The discussion centers on plotting data from a text file in MATLAB, specifically using a network analyzer's output. The user faced challenges in organizing the data for plotting but successfully resolved the issue by utilizing MATLAB's built-in functions. The final solution involved loading the data with the command load file.txt, extracting the X and Y values using x = file(:,1) and y = file(:,2), and plotting them with plot(x,y). This method efficiently handles large datasets without manual reorganization.

PREREQUISITES
  • Familiarity with MATLAB syntax and commands
  • Understanding of data structures in MATLAB
  • Basic knowledge of plotting functions in MATLAB
  • Experience with handling text files in MATLAB
NEXT STEPS
  • Explore MATLAB's data import functions for various file formats
  • Learn about MATLAB's plot function and its customization options
  • Investigate MATLAB's data manipulation capabilities using matrices
  • Study advanced plotting techniques in MATLAB, such as 3D plots and surface plots
USEFUL FOR

This discussion is beneficial for MATLAB users, data analysts, and engineers who need to visualize data from text files, particularly those working with measurement data from network analyzers or similar instruments.

A.J.710
Messages
56
Reaction score
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
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);
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
3
Views
2K