314kabinet-_-

Import data (TXT->TXT through Python)

May 18th, 2023
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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\PRN, TXT\output_python.txt
  5. %
  6. % Auto-generated by MATLAB on 13-Nov-2021 15:45:24
  7.  
  8. %% Setup the Import Options
  9. clear all
  10. clc
  11. opts = delimitedTextImportOptions("NumVariables", 5);
  12.  
  13. % Specify range and delimiter
  14. opts.DataLines = [1, Inf];
  15. opts.Delimiter = " ";
  16.  
  17. % Specify column names and types
  18. opts.VariableNames = ["FREQ", "DEG", "Var3", "Var4", "Var5"];
  19. opts.SelectedVariableNames = ["FREQ", "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\PRN, TXT\output_python.txt", opts);
  32.  
  33. %% Convert to output type
  34. FREQ = tbl.FREQ;
  35. DEG = tbl.DEG;
  36.  
  37.  
  38. %% Clear temporary variables
  39. clear opts tbl
  40. plot(FREQ, DEG);
Add Comment
Please, Sign In to add comment