Advertisement
makispaiktis

Import data (PRN->TXT) 2 files + PLOT

Nov 13th, 2021 (edited)
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.57 KB | None | 0 0
  1. %% Import data from text file
  2. % Script for importing data from the following text file:
  3. %
  4. %    filename: C:\Users\User\Documents\MATLAB\Tutorials\Tutorials Thomas\Importing 2 txt files\Wilkinson_normS21.TXT
  5. %
  6. % Auto-generated by MATLAB on 13-Nov-2021 15:49:12
  7.  
  8. %% Setup the Import Options
  9. clear all
  10. clc
  11. opts = delimitedTextImportOptions("NumVariables", 2);
  12.  
  13. % Specify range and delimiter
  14. opts.DataLines = [4, Inf];
  15. opts.Delimiter = ",";
  16.  
  17. % Specify column names and types
  18. opts.VariableNames = ["FreqMHz", "Deg", "Var3", "Var4", "Var5"];
  19. opts.SelectedVariableNames = ["FreqMHz", "Deg"];
  20. opts.VariableTypes = ["double", "double", "char", "char", "char"];
  21. opts = setvaropts(opts, [3, 4, 5], "WhitespaceRule", "preserve");
  22. opts = setvaropts(opts, 1, "TrimNonNumeric", true);
  23. opts = setvaropts(opts, 1, "ThousandsSeparator", ",");
  24. opts = setvaropts(opts, [3, 4, 5], "EmptyFieldRule", "auto");
  25. opts.ExtraColumnsRule = "ignore";
  26. opts.EmptyLineRule = "read";
  27. opts.ConsecutiveDelimitersRule = "join";
  28. opts.LeadingDelimitersRule = "ignore";
  29.  
  30. % Import the data
  31. tbl = readtable("C:\Users\User\Documents\MATLAB\Tutorials\Tutorials Thomas\Importing 2 txt files\Wilkinson_normS21.TXT", opts);
  32. tbl2 = readtable("C:\Users\User\Documents\MATLAB\Tutorials\Tutorials Thomas\Importing 2 txt files\Wilkinson_normS31.TXT", opts);
  33.  
  34. %% Convert to output type
  35. FreqMHz = tbl.FreqMHz;
  36. Deg = tbl.Deg;
  37. FreqMHz2 = tbl2.FreqMHz;
  38. Deg2 = tbl2.Deg;
  39.  
  40. %% Clear temporary variables
  41. clear opts tbl
  42. plot(FreqMHz, Deg, 'red', FreqMHz2, Deg2, 'blue');
  43. title('S21, S31 (Insertion Loss)');
  44. legend('S21', 'S31');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement