Change from 2022 to 2021 Plotting Issues

3 visualizaciones (últimos 30 días)
Tyler
Tyler el 28 de Nov. de 2022
Comentada: Tyler el 28 de Nov. de 2022
I have this code that is not quite finished yet, however it works on version 2022. Had to change to 2021 for licensing reasons and now it will not plot. HELP!
classdef SEdataAPPv1_03_2 < matlab.ui.componentcontainer.ComponentContainer
% Properties that correspond to app components
properties (Access = private, Transient, NonCopyable)
GridLayout matlab.ui.container.GridLayout
ASEDATAREDUCTIONLabel matlab.ui.control.Label
Version103Label matlab.ui.control.Label
Image matlab.ui.control.Image
PlotSaveNameEditField matlab.ui.control.EditField
PlotSaveNameEditFieldLabel matlab.ui.control.Label
TestPointLocationEditField matlab.ui.control.EditField
TestPointLocationEditFieldLabel matlab.ui.control.Label
StartButton matlab.ui.control.Button
end
% Callbacks that handle component events
methods (Access = private)
% Value changed function: TestPointLocationEditField
function TestPointLocationEditFieldValueChanged(comp, event)
valueTP = comp.TestPointLocationEditField.Value;
end
% Value changed function: PlotSaveNameEditField
function PlotSaveNameEditFieldValueChanged(comp, event)
valuePS = comp.PlotSaveNameEditField.Value;
end
% Button pushed function: StartButton
function StartButtonPushed(comp, event)
% This code takes RAW SE data, turns the files into text (.txt) files and
% then combines the HIGH, MID, and LOW frequency into one text file which
% can be then multi-selected and those selected files will be put onto a
% plot.
% Enter the directory to search
directory = uigetdir('*',"Select Folder With Files To Be Processed");
% List all items in the folder
fileList = dir(directory);
% Delete the subfolders from the list (i.e. only keep files)
fileList(vertcat(fileList.isdir)) = [];
figure
hold all
% Uses folder as title of plot
[ParentFolderPath] = fullfile(directory);
[~, ParentFolderName] = fileparts(ParentFolderPath);
title(ParentFolderName,'FontSize',20);
% Loop through each file, copy it and give new extension: .txt
for i = 1:numel(fileList)
file = fullfile(directory, fileList(i).name);
[tempDir, tempFile] = fileparts(file);
status = copyfile(file, fullfile(tempDir, [tempFile, '.txt']));
end
% Combine HORIZONTAL text files
%location = input("location of test point: ","s");
fileName = comp.TestPointLocationEditField.Value + " HORZ NOM.txt";
dL = dir(fullfile(directory,'*HLF*NOM.txt')); % salt to suit wildcard to match naming convention
dM = dir(fullfile(directory,'*HMF*NOM.txt'));
dH = dir(fullfile(directory,'*HHF*NOM.txt'));
for i = 1:numel(inf) % there must be same number Lo, Mid, High -- add error check first
tD = readtable(fullfile(dL(i).folder,dL(i).name),'numheaderlines',6,'readvariablenames',1);
tD = [tD;readtable(fullfile(dM(i).folder,dM(i).name),'numheaderlines',6,'readvariablenames',1)];
tD = [tD;readtable(fullfile(dH(i).folder,dH(i).name),'numheaderlines',6,'readvariablenames',1)];
% do whatever with each set here before going on...
writetable(tD,fullfile(directory, fileName));
plot(tD,"Frequency","SE","Color",'Blue',LineWidth=1.5);
end
% Combine VERTICAL text files
%location = input("location of test point: ","s");
fileName = comp.TestPointLocationEditField.Value + " VERT NOM.txt";
dL = dir(fullfile(directory,'*VLF*NOM.txt')); % salt to suit wildcard to match naming convention
dM = dir(fullfile(directory,'*VMF*NOM.txt'));
dH = dir(fullfile(directory,'*VHF*NOM.txt'));
for i = 1:numel(inf) % there must be same number Lo, Mid, High -- add error check first
tD = readtable(fullfile(dL(i).folder,dL(i).name),'numheaderlines',6,'readvariablenames',1);
tD = [tD;readtable(fullfile(dM(i).folder,dM(i).name),'numheaderlines',6,'readvariablenames',1)];
tD = [tD;readtable(fullfile(dH(i).folder,dH(i).name),'numheaderlines',6,'readvariablenames',1)];
% do whatever with each set here before going on...
writetable(tD,fullfile(directory, fileName))
plot(tD,"Frequency","SE","Color",'Red',LineWidth=1.5);
end
% Combine AON text files and save as MR
%location = input("location of test point: ","s");
fileName = comp.TestPointLocationEditField.Value + " AON.txt";
dL = dir(fullfile(directory,'*HLF*AON.txt')); % salt to suit wildcard to match naming convention
dM = dir(fullfile(directory,'*HMF*AON.txt'));
dH = dir(fullfile(directory,'*HHF*AON.txt'));
for i = 1:numel(inf) % there must be same number Lo, Mid, High -- add error check first
tD = readtable(fullfile(dL(i).folder,dL(i).name),'numheaderlines',6,'readvariablenames',1);
tD = [tD;readtable(fullfile(dM(i).folder,dM(i).name),'numheaderlines',6,'readvariablenames',1)];
tD = [tD;readtable(fullfile(dH(i).folder,dH(i).name),'numheaderlines',6,'readvariablenames',1)];
% do whatever with each set here before going on...
writetable(tD,fullfile(directory, fileName))
plot(tD,"Frequency","SE","Color",'#588146',LineWidth=1.5);
end
% Combine FTN text files and save as DR
%location = input("location of test point: ","s");
fileName = comp.TestPointLocationEditField.Value + " FTN.txt";
dL = dir(fullfile(directory,'*HLF*FTN.txt')); % salt to suit wildcard to match naming convention
dM = dir(fullfile(directory,'*HMF*FTN.txt'));
dH = dir(fullfile(directory,'*HHF*FTN.txt'));
for i = 1:numel(inf) % there must be same number Lo, Mid, High -- add error check first
tD = readtable(fullfile(dL(i).folder,dL(i).name),'numheaderlines',6,'readvariablenames',1);
tD = [tD;readtable(fullfile(dM(i).folder,dM(i).name),'numheaderlines',6,'readvariablenames',1)];
tD = [tD;readtable(fullfile(dH(i).folder,dH(i).name),'numheaderlines',6,'readvariablenames',1)];
% do whatever with each set here before going on...
writetable(tD,fullfile(directory, fileName))
plot(tD,"Frequency","SE","Color",'#9f9f9f',LineWidth=1.5);
end
grid on
% Changing colors based on alphebetic order
newcolors = {'Blue','Red','#72a75b','#999999','#0003ff'};
colororder(newcolors);
% Sets pass/fail line
PFx = [10000 10000000 1000000000];
PFy = [20 80 80];
% Adds pass/fail line to plot
plot(PFx,PFy,'Color','Green','LineWidth',1.5);
% Changes legend location and removes pass/fail line from legend
Lgnd = legend('Location','northwest');
Lgnd = legend('Horizontal','Vertical','MR','DR','MIL-STD-188-125-1');
Lgnd.FontSize = 14;
% Labels both x and y axis
xlabel('Frequency (Hz)','FontSize',18,'FontWeight','bold');
ylabel('Shielding Effectivness (dB)','FontSize',18,'FontWeight','bold');
% Sets both axis scales
set(gca,'XScale','log','ylim',[-10 200]);
% Removes the values on the plot *Comment out
% set(gca,'xticklabel',[],'yticklabel',[]); to add them back in*
% set(gca,'xticklabel',[],'yticklabel',[]);
% Sets grid lines to dashes, colors
set(gca,'gridlinestyle','--');
set(gca,'gridalpha',0.5);
set(gca,'GridColor','Black');
set(gca,'Color','#ececec');
set(gca,'Color','#ececec');
hold off

Respuesta aceptada

Tyler
Tyler el 28 de Nov. de 2022
I was able to work through it! Thanks everyone!

Más respuestas (1)

Steven Lord
Steven Lord el 28 de Nov. de 2022
The ability to plot table arrays by passing them as inputs to the plot function was introduced in release R2022a as stated in the Release Notes. In an older release follow the suggestion in the error message and either use the stackedplot function to extract the data from the table array and pass the extracted data into plot.
To plot a table or a timetable, use the stackedplot function. As an alternative, extract table or timetable variables using dot or brace subscripting, and then pass the variables as input arguments to the plot function.
  3 comentarios
Steven Lord
Steven Lord el 28 de Nov. de 2022
Index into the table. Let's take a sample table.
load patients
p = table(LastName, Age, Weight);
head(p)
LastName Age Weight ____________ ___ ______ {'Smith' } 38 176 {'Johnson' } 43 163 {'Williams'} 38 131 {'Jones' } 40 133 {'Brown' } 49 119 {'Davis' } 46 142 {'Miller' } 33 142 {'Wilson' } 40 180
Now create a stacked plot with just the Age and Weight variables.
stackedplot(p(:, [2 3]))
Tyler
Tyler el 28 de Nov. de 2022
I ended up making it work. I realized how to use "." when reading tables which I had not needed to ever do before (still fairly new and was using the newer version). Thanks for your time though!

Iniciar sesión para comentar.

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by