Change from 2022 to 2021 Plotting Issues
조회 수: 3 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
추가 답변 (1개)
Steven Lord
2022년 11월 28일
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
Steven Lord
2022년 11월 28일
Index into the table. Let's take a sample table.
load patients
p = table(LastName, Age, Weight);
head(p)
Now create a stacked plot with just the Age and Weight variables.
stackedplot(p(:, [2 3]))
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!