Category: Matlab
Category Archives: Matlab
I am trying to implement a state space solution in Simulink with 1 variable m in matrix C, but the runtime error says Variable ‘m’ does not exist.
I am trying to implement a state space solution in Simulink with 1 variable m in matrix C, but the runtime error says Variable ‘m’ does not exist.
How to assign a value to the variable m?
The callback strings are A=[0 1;-2 -3]; B=[0 1]’; C=[1 0;0 m]; D=[0 ;0];’
Here’s the model I uploaded.I am trying to implement a state space solution in Simulink with 1 variable m in matrix C, but the runtime error says Variable ‘m’ does not exist.
How to assign a value to the variable m?
The callback strings are A=[0 1;-2 -3]; B=[0 1]’; C=[1 0;0 m]; D=[0 ;0];’
Here’s the model I uploaded. I am trying to implement a state space solution in Simulink with 1 variable m in matrix C, but the runtime error says Variable ‘m’ does not exist.
How to assign a value to the variable m?
The callback strings are A=[0 1;-2 -3]; B=[0 1]’; C=[1 0;0 m]; D=[0 ;0];’
Here’s the model I uploaded. simulink, state space MATLAB Answers — New Questions
Should table Indexing be Faster?
Example code.
t = combinations(0:10,0:10,0:10,0:10);
tic
for ii = 1:10
for jj = 1:height(t)
u = t{jj,:};
end
end
toc
tic
tcell = table2cell(t);
for ii = 1:10
for jj = 1:height(tcell)
u = [tcell{jj,:}];
end
end
toc
tic
tarr = table2array(t);
for ii = 1:10
for jj = 1:height(tarr)
u = tarr(jj,:);
end
end
toc
Any ideas why indexing into a table to extract data is so slow?Example code.
t = combinations(0:10,0:10,0:10,0:10);
tic
for ii = 1:10
for jj = 1:height(t)
u = t{jj,:};
end
end
toc
tic
tcell = table2cell(t);
for ii = 1:10
for jj = 1:height(tcell)
u = [tcell{jj,:}];
end
end
toc
tic
tarr = table2array(t);
for ii = 1:10
for jj = 1:height(tarr)
u = tarr(jj,:);
end
end
toc
Any ideas why indexing into a table to extract data is so slow? Example code.
t = combinations(0:10,0:10,0:10,0:10);
tic
for ii = 1:10
for jj = 1:height(t)
u = t{jj,:};
end
end
toc
tic
tcell = table2cell(t);
for ii = 1:10
for jj = 1:height(tcell)
u = [tcell{jj,:}];
end
end
toc
tic
tarr = table2array(t);
for ii = 1:10
for jj = 1:height(tarr)
u = tarr(jj,:);
end
end
toc
Any ideas why indexing into a table to extract data is so slow? tables, indexing MATLAB Answers — New Questions
Fading/shading an image
Good evening,
I had to darken half of a RGB image in order to recreate an emianopsy. Here is the code I used:
%Loss of left visus
A = imread(‘lena .bmp’);
[x,y,z]=size(A); %dimensions’ estraction RGB image
Y=y/2; % halving y axis
HSV = rgb2hsv(A); %conversion to hsv space
%Process the HSV image. This example decrease the brightness of half image by multiplying the V channel by a scale factor.
[h,s,v] = imsplit(HSV); %split hue, saturation and value channels
vFactor = 0.2; %define the scale factor for brightness
% for cicle darken pixels of the left part of the image
for i=1:x
for j=1:Y
v(i,j) = v(i,j)*vFactor;
end
end
HSV_v = cat(3,h,s,v); %reconstrucion of HSV image
%Convert the processed HSV image back to the RGB color space.
Av = hsv2rgb(HSV_v);
figure
imshow(Av)
title(‘Left emianopsy’);
Here is the resulting image:
The separation between the 2 parts of the image is too sharp and marked, so I’d like to obtain a more faded transition between the dark and the coloured side (like a gradient?). How can I obtain a realistic result? like for example the image below:
Thank you in advanceGood evening,
I had to darken half of a RGB image in order to recreate an emianopsy. Here is the code I used:
%Loss of left visus
A = imread(‘lena .bmp’);
[x,y,z]=size(A); %dimensions’ estraction RGB image
Y=y/2; % halving y axis
HSV = rgb2hsv(A); %conversion to hsv space
%Process the HSV image. This example decrease the brightness of half image by multiplying the V channel by a scale factor.
[h,s,v] = imsplit(HSV); %split hue, saturation and value channels
vFactor = 0.2; %define the scale factor for brightness
% for cicle darken pixels of the left part of the image
for i=1:x
for j=1:Y
v(i,j) = v(i,j)*vFactor;
end
end
HSV_v = cat(3,h,s,v); %reconstrucion of HSV image
%Convert the processed HSV image back to the RGB color space.
Av = hsv2rgb(HSV_v);
figure
imshow(Av)
title(‘Left emianopsy’);
Here is the resulting image:
The separation between the 2 parts of the image is too sharp and marked, so I’d like to obtain a more faded transition between the dark and the coloured side (like a gradient?). How can I obtain a realistic result? like for example the image below:
Thank you in advance Good evening,
I had to darken half of a RGB image in order to recreate an emianopsy. Here is the code I used:
%Loss of left visus
A = imread(‘lena .bmp’);
[x,y,z]=size(A); %dimensions’ estraction RGB image
Y=y/2; % halving y axis
HSV = rgb2hsv(A); %conversion to hsv space
%Process the HSV image. This example decrease the brightness of half image by multiplying the V channel by a scale factor.
[h,s,v] = imsplit(HSV); %split hue, saturation and value channels
vFactor = 0.2; %define the scale factor for brightness
% for cicle darken pixels of the left part of the image
for i=1:x
for j=1:Y
v(i,j) = v(i,j)*vFactor;
end
end
HSV_v = cat(3,h,s,v); %reconstrucion of HSV image
%Convert the processed HSV image back to the RGB color space.
Av = hsv2rgb(HSV_v);
figure
imshow(Av)
title(‘Left emianopsy’);
Here is the resulting image:
The separation between the 2 parts of the image is too sharp and marked, so I’d like to obtain a more faded transition between the dark and the coloured side (like a gradient?). How can I obtain a realistic result? like for example the image below:
Thank you in advance image processing, faded image, shade image, color transition MATLAB Answers — New Questions
App Designer has error in generated code
App designer places code (grayed out) that shows an error. I will note that the code ran fine before I saved and closed it out and then later restarted the app. I think the issue might be related to the fact that I had a callback that used the delete function which is used to close the app.
The line that show the syntax error is the following and bold in the full code listing:
app.RawdataPlotterAppUIFigure.CloseRequestFcn = createCallbackFcn(app, @delete(gcf), true);
Full code below:
classdef RawDataPlotterNew < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
RawdataPlotterAppUIFigure matlab.ui.Figure
GridLayout matlab.ui.container.GridLayout
LeftPanel matlab.ui.container.Panel
ControlPanel matlab.ui.container.Panel
SelectDataFileButton matlab.ui.control.Button
QuitButton matlab.ui.control.Button
ChannelSelectPanel matlab.ui.container.Panel
Select355CheckBox matlab.ui.control.CheckBox
Select532CheckBox matlab.ui.control.CheckBox
Select1064CheckBox matlab.ui.control.CheckBox
DelaysEditField matlab.ui.control.NumericEditField
DelaysEditFieldLabel matlab.ui.control.Label
StepDownButton matlab.ui.control.Button
AltMaxEditField matlab.ui.control.NumericEditField
AltMaxEditFieldLabel matlab.ui.control.Label
AltMinEditField matlab.ui.control.NumericEditField
AltMinEditFieldLabel matlab.ui.control.Label
CountsMaxEditField matlab.ui.control.NumericEditField
CountsMaxEditFieldLabel matlab.ui.control.Label
CountsMinEditField matlab.ui.control.NumericEditField
CountsMinEditFieldLabel matlab.ui.control.Label
AutoScaleYCheckBox matlab.ui.control.CheckBox
AutoScaleXCheckBox matlab.ui.control.CheckBox
LegendCheckBox matlab.ui.control.CheckBox
LogScaleCheckBox matlab.ui.control.CheckBox
RangeSquaredCheckBox matlab.ui.control.CheckBox
RunButton matlab.ui.control.StateButton
StepUpButton matlab.ui.control.Button
RecordEditField matlab.ui.control.NumericEditField
RecordEditFieldLabel matlab.ui.control.Label
TimeEditField matlab.ui.control.NumericEditField
TimeEditFieldLabel matlab.ui.control.Label
Channel4DropDown matlab.ui.control.DropDown
Channel4DropDownLabel matlab.ui.control.Label
Channel3DropDown matlab.ui.control.DropDown
Channel3DropDownLabel matlab.ui.control.Label
Channel2DropDown matlab.ui.control.DropDown
Channel2DropDownLabel matlab.ui.control.Label
Channel1DropDown matlab.ui.control.DropDown
Channel1DropDownLabel matlab.ui.control.Label
RightPanel matlab.ui.container.Panel
Panel4 matlab.ui.container.Panel
StatusEditField matlab.ui.control.EditField
StatusEditFieldLabel matlab.ui.control.Label
PathnameEditField matlab.ui.control.EditField
PathnameEditFieldLabel matlab.ui.control.Label
FilenameEditField matlab.ui.control.EditField
FilenameEditFieldLabel matlab.ui.control.Label
Panel3 matlab.ui.container.Panel
UIAxes matlab.ui.control.UIAxes
end
% Properties that correspond to apps with auto-reflow
properties (Access = private)
onePanelWidth = 576;
end
properties (Access = private)
FileName; % File for rawdata file being plotted
PathName; % Path for rawdata file being plotted
FullFileName; %Full filename
ChannelNames; %Names of the channels in data file
Altitude; %Altitude from raw data file
TimeUT; %time from rawdata file
SelectedChannels; %array of selected channels
CurrentRecord; %record index
CurrentTimeUT; %current time of data record
data; % data from selected channels
range; % range data for all PMT channels
range50; % range data for all APD channels
NumChannels = 4;
goodFileSelected = 0; %toggle to make sure a good file is selected
end
methods (Access = private)
function updatePlot(app)
getSelectedChannels(app)
for idx=1:app.NumChannels
if app.RangeSquaredCheckBox.Value
x = squeeze(app.data(:,app.CurrentRecord,idx));
else
if contains(app.SelectedChannels(idx),’1064′)
x = squeeze(app.data(:,app.CurrentRecord,idx))./(app.range50(:,app.CurrentRecord)).^2;
else
x = squeeze(app.data(:,app.CurrentRecord,idx))./(app.range(:,app.CurrentRecord)).^2;
end
end
plot(app.UIAxes,x,app.Altitude);
hold(app.UIAxes,’on’)
end
hold(app.UIAxes,’off’)
%scale axes
if app.AutoScaleXCheckBox.Value
xlim(app.UIAxes,[0,2^16]);
else
xlim(app.UIAxes, [app.CountsMinEditField.Value,app.CountsMaxEditField.Value]);
end
if app.AutoScaleYCheckBox.Value
ylim(app.UIAxes, [min(app.Altitude),max(app.Altitude)]);
else
ylim(app.UIAxes, [app.AltMinEditField.Value,app.AltMaxEditField.Value]);
end
%check log scale
if app.LogScaleCheckBox.Value == 1
xscale(app.UIAxes,"log");
else
xscale(app.UIAxes,"linear");
end
%add legend
if app.LegendCheckBox.Value
legend(app.UIAxes,app.SelectedChannels,’Interpreter’, ‘none’)
else
legend(app.UIAxes,’off’)
end
drawnow;
end
function getSelectedChannels(app)
channel(1) = app.Channel1DropDown.ValueIndex;
channel(2) = app.Channel2DropDown.ValueIndex;
channel(3) = app.Channel3DropDown.ValueIndex;
channel(4) = app.Channel4DropDown.ValueIndex;
for idx=1:app.NumChannels
app.SelectedChannels{idx} = app.ChannelNames{channel(idx)};
end
end
function updateData(app)
if app.goodFileSelected
%always update selected channels
getSelectedChannels(app);
for idx=1:app.NumChannels
if contains(app.SelectedChannels{idx},’None’)
app.data(:,:,idx) = NaN(size(app.Altitude,1),size(app.TimeUT,2));
else
dataName = [‘/CLDSData/’,app.SelectedChannels{idx}];
app.data(:,:,idx) = h5read(app.FullFileName,dataName);
end
end
else
app.StatusEditField.Value = ‘Not correct type of data file (LBW or HBW)’;
end
end
function updateDataSingleChannel(app,idx)
if app.goodFileSelected
%always update selected channels
getSelectedChannels(app);
if contains(app.SelectedChannels{idx},’None’)
app.data(:,:,idx) = NaN(size(app.Altitude,1),size(app.TimeUT,2));
else
dataName = [‘/CLDSData/’,app.SelectedChannels{idx}];
app.data(:,:,idx) = h5read(app.FullFileName,dataName);
end
else
app.StatusEditField.Value = ‘Not correct type of data file (LBW or HBW)’;
end
end
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
SelectDataFileButtonPushed(app, [])
end
% Button pushed function: QuitButton
function QuitButtonPushed(app, event)
delete(app)
end
% Button pushed function: SelectDataFileButton
function SelectDataFileButtonPushed(app, event)
defname = ‘/Users/Shared/Data/’;
[app.FileName,app.PathName] = uigetfile(‘.h5′,’Select H5 File’,defname);
app.FilenameEditField.Value = app.FileName;
app.PathnameEditField.Value = app.PathName;
app.FullFileName = fullfile(app.PathName,app.FileName);
%get channel names and populate the dropdown lists
%do try catch to see if data file is correct
try
app.ChannelNames = h5read(app.FullFileName,’/Channel_Names’);
selectIdx = contains(app.ChannelNames,’high’);
app.ChannelNames = app.ChannelNames(selectIdx);
app.ChannelNames = [{‘None’};app.ChannelNames];
app.Channel1DropDown.Items = app.ChannelNames;
app.Channel2DropDown.Items = app.ChannelNames;
app.Channel3DropDown.Items = app.ChannelNames;
app.Channel4DropDown.Items = app.ChannelNames;
catch
app.StatusEditField.Value = ‘Not correct type of data file (LBW or HBW)’;
end
%load in the altitude and time data
try
app.Altitude = h5read(app.FullFileName,’/DataProducts/Altitude’)/1000;
app.TimeUT = h5read(app.FullFileName,’/Nav_Data/gps_time’);
app.CurrentRecord = 1;
app.CurrentTimeUT = app.TimeUT(app.CurrentRecord);
app.TimeEditField.Value = app.TimeUT(app.CurrentRecord);
app.RecordEditField.Value = app.CurrentRecord;
app.goodFileSelected = 1;
catch
app.StatusEditField.Value = ‘Issue reading altitude or time from data file’;
end
%get range data
app.range = h5read(app.FullFileName,’/UserInput/range_interp’);
app.range50 = h5read(app.FullFileName,’/UserInput/range50_interp’);
%initialize data array to NaN
app.data = NaN(size(app.Altitude,1),size(app.TimeUT,2),app.NumChannels);
%set limits on record and time values
app.RecordEditField.Limits = [1,size(app.TimeUT,2)];
app.TimeEditField.Limits = [min(app.TimeUT),max(app.TimeUT)];
%update data
updateData(app);
%plot data
updatePlot(app);
end
% Value changed function: RecordEditField
function RecordEditFieldValueChanged(app, event)
value = app.RecordEditField.Value;
app.CurrentRecord = value;
app.TimeEditField.Value = app.TimeUT(app.CurrentRecord);
updatePlot(app)
end
% Value changed function: TimeEditField
function TimeEditFieldValueChanged(app, event)
value = app.TimeEditField.Value;
if value <= app.TimeUT(1,end)
idx = find(app.TimeUT>=value,1,’first’);
else
idx = size(app.TimeUT,2);
end
app.CurrentTimeUT = app.TimeUT(idx);
app.RecordValue.Value = idx;
updatePlot(app)
end
% Value changed function: Channel1DropDown
function Channel1DropDownValueChanged(app, event)
updateDataSingleChannel(app,1);
updatePlot(app);
end
% Value changed function: Channel2DropDown
function Channel2DropDownValueChanged(app, event)
updateDataSingleChannel(app,2);
updatePlot(app);
end
% Value changed function: Channel3DropDown
function Channel3DropDownValueChanged(app, event)
updateDataSingleChannel(app,3);
updatePlot(app);
end
% Value changed function: Channel4DropDown
function Channel4DropDownValueChanged(app, event)
updateDataSingleChannel(app,4);
updatePlot(app);
end
% Value changed function: LogScaleCheckBox
function LogScaleCheckBoxValueChanged(app, event)
updatePlot(app);
end
% Value changed function: LegendCheckBox
function LegendCheckBoxValueChanged(app, event)
updatePlot(app);
end
% Value changed function: CountsMaxEditField
function CountsMaxEditFieldValueChanged(app, event)
updatePlot(app)
end
% Value changed function: CountsMinEditField
function CountsMinEditFieldValueChanged(app, event)
updatePlot(app)
end
% Value changed function: AltMinEditField
function AltMinEditFieldValueChanged(app, event)
updatePlot(app)
end
% Value changed function: AltMaxEditField
function AltMaxEditFieldValueChanged(app, event)
updatePlot(app)
end
% Button pushed function: StepUpButton
function StepUpButtonPushed(app, event)
app.RecordEditField.Value = app.RecordEditField.Value+1;
app.CurrentRecord = app.RecordEditField.Value;
app.TimeEditField.Value = app.TimeUT(app.CurrentRecord);
updatePlot(app)
end
% Button pushed function: StepDownButton
function StepDownButtonPushed(app, event)
app.RecordEditField.Value = app.RecordEditField.Value-1;
app.CurrentRecord = app.RecordEditField.Value;
app.TimeEditField.Value = app.TimeUT(app.CurrentRecord);
updatePlot(app)
end
% Value changed function: RunButton
function RunButtonValueChanged(app, event)
value = app.RunButton.Value;
while value == 1
app.RunButton.Text = ‘Stop’;
app.RunButton.BackgroundColor = [1,0,0];
app.RecordEditField.Value = app.RecordEditField.Value+1;
app.CurrentRecord = app.RecordEditField.Value;
app.TimeEditField.Value = app.TimeUT(app.CurrentRecord);
pause(app.DelaysEditField.Value)
updatePlot(app)
value = app.RunButton.Value;
end
app.RunButton.Text = ‘Run’;
app.RunButton.BackgroundColor = [0.96,0.96,0.96];
end
% Value changed function: Select1064CheckBox
function Select1064CheckBoxValueChanged(app, event)
%uncheck other wavelengths (only one possible)
app.Select532CheckBox.Value = 0;
app.Select355CheckBox.Value = 0;
%set dropdown lists for 1064
app.Channel1DropDown.ValueIndex = 2;
app.Channel2DropDown.ValueIndex = 3;
app.Channel3DropDown.ValueIndex = 1;
app.Channel4DropDown.ValueIndex = 1;
updateData(app);
updatePlot(app)
end
% Value changed function: Select532CheckBox
function Select532CheckBoxValueChanged(app, event)
%uncheck other wavelengths (only one possible)
app.Select1064CheckBox.Value = 0;
app.Select355CheckBox.Value = 0;
%set dropdown lists for 1064
app.Channel1DropDown.ValueIndex = 4;
app.Channel2DropDown.ValueIndex = 5;
app.Channel3DropDown.ValueIndex = 6;
app.Channel4DropDown.ValueIndex = 1;
updateData(app);
updatePlot(app);
end
% Value changed function: Select355CheckBox
function Select355CheckBoxValueChanged(app, event)
%uncheck other wavelengths (only one possible)
app.Select1064CheckBox.Value = 0;
app.Select532CheckBox.Value = 0;
%set dropdown lists for 1064
app.Channel1DropDown.ValueIndex = 7;
app.Channel2DropDown.ValueIndex = 8;
app.Channel3DropDown.ValueIndex = 9;
app.Channel4DropDown.ValueIndex = 10;
updateData(app);
updatePlot(app);
end
% Value changed function: DelaysEditField
function DelaysEditFieldValueChanged(app, event)
value = app.DelaysEditField.Value;
if value < 0.05
app.DelaysEditField.Value = 0.05;
end
end
% Changes arrangement of the app based on UIFigure width
function updateAppLayout(app, event)
currentFigureWidth = app.RawdataPlotterAppUIFigure.Position(3);
if(currentFigureWidth <= app.onePanelWidth)
% Change to a 2×1 grid
app.GridLayout.RowHeight = {642, 642};
app.GridLayout.ColumnWidth = {‘1x’};
app.RightPanel.Layout.Row = 2;
app.RightPanel.Layout.Column = 1;
else
% Change to a 1×2 grid
app.GridLayout.RowHeight = {‘1x’};
app.GridLayout.ColumnWidth = {220, ‘1x’};
app.RightPanel.Layout.Row = 1;
app.RightPanel.Layout.Column = 2;
end
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create RawdataPlotterAppUIFigure and hide until all components are created
app.RawdataPlotterAppUIFigure = uifigure(‘Visible’, ‘off’);
app.RawdataPlotterAppUIFigure.AutoResizeChildren = ‘off’;
app.RawdataPlotterAppUIFigure.Position = [100 100 719 642];
app.RawdataPlotterAppUIFigure.Name = ‘Rawdata Plotter App’;
app.RawdataPlotterAppUIFigure.CloseRequestFcn = createCallbackFcn(app, @delete(gcf), true); %MARKED
app.RawdataPlotterAppUIFigure.SizeChangedFcn = createCallbackFcn(app, @updateAppLayout, true);
% Create GridLayout
app.GridLayout = uigridlayout(app.RawdataPlotterAppUIFigure);
app.GridLayout.ColumnWidth = {220, ‘1x’};
app.GridLayout.RowHeight = {‘1x’};
app.GridLayout.ColumnSpacing = 0;
app.GridLayout.RowSpacing = 0;
app.GridLayout.Padding = [0 0 0 0];
app.GridLayout.Scrollable = ‘on’;
% Create LeftPanel
app.LeftPanel = uipanel(app.GridLayout);
app.LeftPanel.Layout.Row = 1;
app.LeftPanel.Layout.Column = 1;
% Create ChannelSelectPanel
app.ChannelSelectPanel = uipanel(app.LeftPanel);
app.ChannelSelectPanel.Title = ‘Channel Select’;
app.ChannelSelectPanel.Position = [9 132 203 502];
% Create Channel1DropDownLabel
app.Channel1DropDownLabel = uilabel(app.ChannelSelectPanel);
app.Channel1DropDownLabel.HorizontalAlignment = ‘right’;
app.Channel1DropDownLabel.Position = [19 446 59 22];
app.Channel1DropDownLabel.Text = ‘Channel 1’;
% Create Channel1DropDown
app.Channel1DropDown = uidropdown(app.ChannelSelectPanel);
app.Channel1DropDown.ValueChangedFcn = createCallbackFcn(app, @Channel1DropDownValueChanged, true);
app.Channel1DropDown.Position = [93 446 100 22];
% Create Channel2DropDownLabel
app.Channel2DropDownLabel = uilabel(app.ChannelSelectPanel);
app.Channel2DropDownLabel.HorizontalAlignment = ‘right’;
app.Channel2DropDownLabel.Position = [19 412 59 22];
app.Channel2DropDownLabel.Text = ‘Channel 2’;
% Create Channel2DropDown
app.Channel2DropDown = uidropdown(app.ChannelSelectPanel);
app.Channel2DropDown.ValueChangedFcn = createCallbackFcn(app, @Channel2DropDownValueChanged, true);
app.Channel2DropDown.Position = [93 412 100 22];
% Create Channel3DropDownLabel
app.Channel3DropDownLabel = uilabel(app.ChannelSelectPanel);
app.Channel3DropDownLabel.HorizontalAlignment = ‘right’;
app.Channel3DropDownLabel.Position = [19 378 59 22];
app.Channel3DropDownLabel.Text = ‘Channel 3’;
% Create Channel3DropDown
app.Channel3DropDown = uidropdown(app.ChannelSelectPanel);
app.Channel3DropDown.ValueChangedFcn = createCallbackFcn(app, @Channel3DropDownValueChanged, true);
app.Channel3DropDown.Position = [93 378 100 22];
% Create Channel4DropDownLabel
app.Channel4DropDownLabel = uilabel(app.ChannelSelectPanel);
app.Channel4DropDownLabel.HorizontalAlignment = ‘right’;
app.Channel4DropDownLabel.Position = [19 345 59 22];
app.Channel4DropDownLabel.Text = ‘Channel 4’;
% Create Channel4DropDown
app.Channel4DropDown = uidropdown(app.ChannelSelectPanel);
app.Channel4DropDown.ValueChangedFcn = createCallbackFcn(app, @Channel4DropDownValueChanged, true);
app.Channel4DropDown.Position = [93 345 100 22];
% Create TimeEditFieldLabel
app.TimeEditFieldLabel = uilabel(app.ChannelSelectPanel);
app.TimeEditFieldLabel.HorizontalAlignment = ‘right’;
app.TimeEditFieldLabel.Position = [36 210 31 22];
app.TimeEditFieldLabel.Text = ‘Time’;
% Create TimeEditField
app.TimeEditField = uieditfield(app.ChannelSelectPanel, ‘numeric’);
app.TimeEditField.ValueDisplayFormat = ‘%11.6g’;
app.TimeEditField.ValueChangedFcn = createCallbackFcn(app, @TimeEditFieldValueChanged, true);
app.TimeEditField.Position = [77 210 100 22];
% Create RecordEditFieldLabel
app.RecordEditFieldLabel = uilabel(app.ChannelSelectPanel);
app.RecordEditFieldLabel.HorizontalAlignment = ‘right’;
app.RecordEditFieldLabel.Position = [25 185 44 22];
app.RecordEditFieldLabel.Text = ‘Record’;
% Create RecordEditField
app.RecordEditField = uieditfield(app.ChannelSelectPanel, ‘numeric’);
app.RecordEditField.ValueChangedFcn = createCallbackFcn(app, @RecordEditFieldValueChanged, true);
app.RecordEditField.Position = [77 185 100 22];
% Create StepUpButton
app.StepUpButton = uibutton(app.ChannelSelectPanel, ‘push’);
app.StepUpButton.ButtonPushedFcn = createCallbackFcn(app, @StepUpButtonPushed, true);
app.StepUpButton.Position = [109 154 66 23];
app.StepUpButton.Text = ‘Step Up’;
% Create RunButton
app.RunButton = uibutton(app.ChannelSelectPanel, ‘state’);
app.RunButton.ValueChangedFcn = createCallbackFcn(app, @RunButtonValueChanged, true);
app.RunButton.Text = ‘Run’;
app.RunButton.Position = [57 8 60 23];
% Create RangeSquaredCheckBox
app.RangeSquaredCheckBox = uicheckbox(app.ChannelSelectPanel);
app.RangeSquaredCheckBox.Text = ‘Range Squared’;
app.RangeSquaredCheckBox.Position = [9 82 105 22];
% Create LogScaleCheckBox
app.LogScaleCheckBox = uicheckbox(app.ChannelSelectPanel);
app.LogScaleCheckBox.ValueChangedFcn = createCallbackFcn(app, @LogScaleCheckBoxValueChanged, true);
app.LogScaleCheckBox.Text = ‘Log Scale’;
app.LogScaleCheckBox.Position = [9 61 76 22];
app.LogScaleCheckBox.Value = true;
% Create LegendCheckBox
app.LegendCheckBox = uicheckbox(app.ChannelSelectPanel);
app.LegendCheckBox.ValueChangedFcn = createCallbackFcn(app, @LegendCheckBoxValueChanged, true);
app.LegendCheckBox.Text = ‘Legend’;
app.LegendCheckBox.Position = [9 40 62 22];
app.LegendCheckBox.Value = true;
% Create AutoScaleXCheckBox
app.AutoScaleXCheckBox = uicheckbox(app.ChannelSelectPanel);
app.AutoScaleXCheckBox.Text = ‘Auto Scale X’;
app.AutoScaleXCheckBox.Position = [9 123 91 22];
app.AutoScaleXCheckBox.Value = true;
% Create AutoScaleYCheckBox
app.AutoScaleYCheckBox = uicheckbox(app.ChannelSelectPanel);
app.AutoScaleYCheckBox.Text = ‘Auto Scale Y’;
app.AutoScaleYCheckBox.Position = [9 103 91 22];
app.AutoScaleYCheckBox.Value = true;
% Create CountsMinEditFieldLabel
app.CountsMinEditFieldLabel = uilabel(app.ChannelSelectPanel);
app.CountsMinEditFieldLabel.HorizontalAlignment = ‘right’;
app.CountsMinEditFieldLabel.Position = [22 308 67 22];
app.CountsMinEditFieldLabel.Text = ‘Counts Min’;
% Create CountsMinEditField
app.CountsMinEditField = uieditfield(app.ChannelSelectPanel, ‘numeric’);
app.CountsMinEditField.ValueChangedFcn = createCallbackFcn(app, @CountsMinEditFieldValueChanged, true);
app.CountsMinEditField.Position = [25 288 66 22];
app.CountsMinEditField.Value = 0.1;
% Create CountsMaxEditFieldLabel
app.CountsMaxEditFieldLabel = uilabel(app.ChannelSelectPanel);
app.CountsMaxEditFieldLabel.HorizontalAlignment = ‘right’;
app.CountsMaxEditFieldLabel.Position = [104 308 70 22];
app.CountsMaxEditFieldLabel.Text = ‘Counts Max’;
% Create CountsMaxEditField
app.CountsMaxEditField = uieditfield(app.ChannelSelectPanel, ‘numeric’);
app.CountsMaxEditField.ValueChangedFcn = createCallbackFcn(app, @CountsMaxEditFieldValueChanged, true);
app.CountsMaxEditField.Position = [104 288 70 22];
app.CountsMaxEditField.Value = 65536;
% Create AltMinEditFieldLabel
app.AltMinEditFieldLabel = uilabel(app.ChannelSelectPanel);
app.AltMinEditFieldLabel.HorizontalAlignment = ‘right’;
app.AltMinEditFieldLabel.Position = [36 267 42 22];
app.AltMinEditFieldLabel.Text = ‘Alt Min’;
% Create AltMinEditField
app.AltMinEditField = uieditfield(app.ChannelSelectPanel, ‘numeric’);
app.AltMinEditField.ValueChangedFcn = createCallbackFcn(app, @AltMinEditFieldValueChanged, true);
app.AltMinEditField.Position = [25 246 66 22];
app.AltMinEditField.Value = -500;
% Create AltMaxEditFieldLabel
app.AltMaxEditFieldLabel = uilabel(app.ChannelSelectPanel);
app.AltMaxEditFieldLabel.HorizontalAlignment = ‘right’;
app.AltMaxEditFieldLabel.Position = [114 267 46 22];
app.AltMaxEditFieldLabel.Text = ‘Alt Max’;
% Create AltMaxEditField
app.AltMaxEditField = uieditfield(app.ChannelSelectPanel, ‘numeric’);
app.AltMaxEditField.ValueChangedFcn = createCallbackFcn(app, @AltMaxEditFieldValueChanged, true);
app.AltMaxEditField.Position = [104 246 69 22];
app.AltMaxEditField.Value = 22000;
% Create StepDownButton
app.StepDownButton = uibutton(app.ChannelSelectPanel, ‘push’);
app.StepDownButton.ButtonPushedFcn = createCallbackFcn(app, @StepDownButtonPushed, true);
app.StepDownButton.Position = [24 154 75 23];
app.StepDownButton.Text = ‘Step Down’;
% Create DelaysEditFieldLabel
app.DelaysEditFieldLabel = uilabel(app.ChannelSelectPanel);
app.DelaysEditFieldLabel.HorizontalAlignment = ‘right’;
app.DelaysEditFieldLabel.Position = [119 34 51 22];
app.DelaysEditFieldLabel.Text = ‘Delay (s)’;
% Create DelaysEditField
app.DelaysEditField = uieditfield(app.ChannelSelectPanel, ‘numeric’);
app.DelaysEditField.ValueChangedFcn = createCallbackFcn(app, @DelaysEditFieldValueChanged, true);
app.DelaysEditField.Position = [128 9 34 22];
app.DelaysEditField.Value = 1;
% Create Select1064CheckBox
app.Select1064CheckBox = uicheckbox(app.ChannelSelectPanel);
app.Select1064CheckBox.ValueChangedFcn = createCallbackFcn(app, @Select1064CheckBoxValueChanged, true);
app.Select1064CheckBox.Text = ‘Select 1064’;
app.Select1064CheckBox.Position = [119 124 86 22];
% Create Select532CheckBox
app.Select532CheckBox = uicheckbox(app.ChannelSelectPanel);
app.Select532CheckBox.ValueChangedFcn = createCallbackFcn(app, @Select532CheckBoxValueChanged, true);
app.Select532CheckBox.Text = ‘Select 532’;
app.Select532CheckBox.Position = [119 101 79 22];
% Create Select355CheckBox
app.Select355CheckBox = uicheckbox(app.ChannelSelectPanel);
app.Select355CheckBox.ValueChangedFcn = createCallbackFcn(app, @Select355CheckBoxValueChanged, true);
app.Select355CheckBox.Text = ‘Select 355’;
app.Select355CheckBox.Position = [119 79 79 22];
% Create ControlPanel
app.ControlPanel = uipanel(app.LeftPanel);
app.ControlPanel.Title = ‘Control’;
app.ControlPanel.Position = [9 13 203 110];
% Create QuitButton
app.QuitButton = uibutton(app.ControlPanel, ‘push’);
app.QuitButton.ButtonPushedFcn = createCallbackFcn(app, @QuitButtonPushed, true);
app.QuitButton.FontWeight = ‘bold’;
app.QuitButton.FontColor = [1 0 0];
app.QuitButton.Position = [57 12 100 23];
app.QuitButton.Text = ‘Quit’;
% Create SelectDataFileButton
app.SelectDataFileButton = uibutton(app.ControlPanel, ‘push’);
app.SelectDataFileButton.ButtonPushedFcn = createCallbackFcn(app, @SelectDataFileButtonPushed, true);
app.SelectDataFileButton.Position = [57 54 100 23];
app.SelectDataFileButton.Text = ‘Select Data File’;
% Create RightPanel
app.RightPanel = uipanel(app.GridLayout);
app.RightPanel.Layout.Row = 1;
app.RightPanel.Layout.Column = 2;
% Create Panel3
app.Panel3 = uipanel(app.RightPanel);
app.Panel3.Title = ‘Panel3’;
app.Panel3.Position = [9 142 481 493];
% Create UIAxes
app.UIAxes = uiaxes(app.Panel3);
xlabel(app.UIAxes, ‘Counts’)
ylabel(app.UIAxes, ‘Altitude (km)’)
zlabel(app.UIAxes, ‘Z’)
app.UIAxes.GridLineWidth = 0.5;
app.UIAxes.MinorGridLineWidth = 0.5;
app.UIAxes.LineWidth = 0.5;
app.UIAxes.Box = ‘off’;
app.UIAxes.FontSize = 14;
app.UIAxes.Position = [4 0 475 469];
% Create Panel4
app.Panel4 = uipanel(app.RightPanel);
app.Panel4.Title = ‘Panel4’;
app.Panel4.Position = [9 10 479 123];
% Create FilenameEditFieldLabel
app.FilenameEditFieldLabel = uilabel(app.Panel4);
app.FilenameEditFieldLabel.HorizontalAlignment = ‘right’;
app.FilenameEditFieldLabel.Position = [14 75 53 22];
app.FilenameEditFieldLabel.Text = ‘Filename’;
% Create FilenameEditField
app.FilenameEditField = uieditfield(app.Panel4, ‘text’);
app.FilenameEditField.Position = [82 75 388 22];
% Create PathnameEditFieldLabel
app.PathnameEditFieldLabel = uilabel(app.Panel4);
app.PathnameEditFieldLabel.HorizontalAlignment = ‘right’;
app.PathnameEditFieldLabel.Position = [8 47 59 22];
app.PathnameEditFieldLabel.Text = ‘Pathname’;
% Create PathnameEditField
app.PathnameEditField = uieditfield(app.Panel4, ‘text’);
app.PathnameEditField.Position = [82 47 388 22];
% Create StatusEditFieldLabel
app.StatusEditFieldLabel = uilabel(app.Panel4);
app.StatusEditFieldLabel.HorizontalAlignment = ‘right’;
app.StatusEditFieldLabel.Position = [28 19 39 22];
app.StatusEditFieldLabel.Text = ‘Status’;
% Create StatusEditField
app.StatusEditField = uieditfield(app.Panel4, ‘text’);
app.StatusEditField.Position = [82 19 388 22];
% Show the figure after all components are created
app.RawdataPlotterAppUIFigure.Visible = ‘on’;
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = RawDataPlotterNew
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.RawdataPlotterAppUIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.RawdataPlotterAppUIFigure)
end
end
endApp designer places code (grayed out) that shows an error. I will note that the code ran fine before I saved and closed it out and then later restarted the app. I think the issue might be related to the fact that I had a callback that used the delete function which is used to close the app.
The line that show the syntax error is the following and bold in the full code listing:
app.RawdataPlotterAppUIFigure.CloseRequestFcn = createCallbackFcn(app, @delete(gcf), true);
Full code below:
classdef RawDataPlotterNew < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
RawdataPlotterAppUIFigure matlab.ui.Figure
GridLayout matlab.ui.container.GridLayout
LeftPanel matlab.ui.container.Panel
ControlPanel matlab.ui.container.Panel
SelectDataFileButton matlab.ui.control.Button
QuitButton matlab.ui.control.Button
ChannelSelectPanel matlab.ui.container.Panel
Select355CheckBox matlab.ui.control.CheckBox
Select532CheckBox matlab.ui.control.CheckBox
Select1064CheckBox matlab.ui.control.CheckBox
DelaysEditField matlab.ui.control.NumericEditField
DelaysEditFieldLabel matlab.ui.control.Label
StepDownButton matlab.ui.control.Button
AltMaxEditField matlab.ui.control.NumericEditField
AltMaxEditFieldLabel matlab.ui.control.Label
AltMinEditField matlab.ui.control.NumericEditField
AltMinEditFieldLabel matlab.ui.control.Label
CountsMaxEditField matlab.ui.control.NumericEditField
CountsMaxEditFieldLabel matlab.ui.control.Label
CountsMinEditField matlab.ui.control.NumericEditField
CountsMinEditFieldLabel matlab.ui.control.Label
AutoScaleYCheckBox matlab.ui.control.CheckBox
AutoScaleXCheckBox matlab.ui.control.CheckBox
LegendCheckBox matlab.ui.control.CheckBox
LogScaleCheckBox matlab.ui.control.CheckBox
RangeSquaredCheckBox matlab.ui.control.CheckBox
RunButton matlab.ui.control.StateButton
StepUpButton matlab.ui.control.Button
RecordEditField matlab.ui.control.NumericEditField
RecordEditFieldLabel matlab.ui.control.Label
TimeEditField matlab.ui.control.NumericEditField
TimeEditFieldLabel matlab.ui.control.Label
Channel4DropDown matlab.ui.control.DropDown
Channel4DropDownLabel matlab.ui.control.Label
Channel3DropDown matlab.ui.control.DropDown
Channel3DropDownLabel matlab.ui.control.Label
Channel2DropDown matlab.ui.control.DropDown
Channel2DropDownLabel matlab.ui.control.Label
Channel1DropDown matlab.ui.control.DropDown
Channel1DropDownLabel matlab.ui.control.Label
RightPanel matlab.ui.container.Panel
Panel4 matlab.ui.container.Panel
StatusEditField matlab.ui.control.EditField
StatusEditFieldLabel matlab.ui.control.Label
PathnameEditField matlab.ui.control.EditField
PathnameEditFieldLabel matlab.ui.control.Label
FilenameEditField matlab.ui.control.EditField
FilenameEditFieldLabel matlab.ui.control.Label
Panel3 matlab.ui.container.Panel
UIAxes matlab.ui.control.UIAxes
end
% Properties that correspond to apps with auto-reflow
properties (Access = private)
onePanelWidth = 576;
end
properties (Access = private)
FileName; % File for rawdata file being plotted
PathName; % Path for rawdata file being plotted
FullFileName; %Full filename
ChannelNames; %Names of the channels in data file
Altitude; %Altitude from raw data file
TimeUT; %time from rawdata file
SelectedChannels; %array of selected channels
CurrentRecord; %record index
CurrentTimeUT; %current time of data record
data; % data from selected channels
range; % range data for all PMT channels
range50; % range data for all APD channels
NumChannels = 4;
goodFileSelected = 0; %toggle to make sure a good file is selected
end
methods (Access = private)
function updatePlot(app)
getSelectedChannels(app)
for idx=1:app.NumChannels
if app.RangeSquaredCheckBox.Value
x = squeeze(app.data(:,app.CurrentRecord,idx));
else
if contains(app.SelectedChannels(idx),’1064′)
x = squeeze(app.data(:,app.CurrentRecord,idx))./(app.range50(:,app.CurrentRecord)).^2;
else
x = squeeze(app.data(:,app.CurrentRecord,idx))./(app.range(:,app.CurrentRecord)).^2;
end
end
plot(app.UIAxes,x,app.Altitude);
hold(app.UIAxes,’on’)
end
hold(app.UIAxes,’off’)
%scale axes
if app.AutoScaleXCheckBox.Value
xlim(app.UIAxes,[0,2^16]);
else
xlim(app.UIAxes, [app.CountsMinEditField.Value,app.CountsMaxEditField.Value]);
end
if app.AutoScaleYCheckBox.Value
ylim(app.UIAxes, [min(app.Altitude),max(app.Altitude)]);
else
ylim(app.UIAxes, [app.AltMinEditField.Value,app.AltMaxEditField.Value]);
end
%check log scale
if app.LogScaleCheckBox.Value == 1
xscale(app.UIAxes,"log");
else
xscale(app.UIAxes,"linear");
end
%add legend
if app.LegendCheckBox.Value
legend(app.UIAxes,app.SelectedChannels,’Interpreter’, ‘none’)
else
legend(app.UIAxes,’off’)
end
drawnow;
end
function getSelectedChannels(app)
channel(1) = app.Channel1DropDown.ValueIndex;
channel(2) = app.Channel2DropDown.ValueIndex;
channel(3) = app.Channel3DropDown.ValueIndex;
channel(4) = app.Channel4DropDown.ValueIndex;
for idx=1:app.NumChannels
app.SelectedChannels{idx} = app.ChannelNames{channel(idx)};
end
end
function updateData(app)
if app.goodFileSelected
%always update selected channels
getSelectedChannels(app);
for idx=1:app.NumChannels
if contains(app.SelectedChannels{idx},’None’)
app.data(:,:,idx) = NaN(size(app.Altitude,1),size(app.TimeUT,2));
else
dataName = [‘/CLDSData/’,app.SelectedChannels{idx}];
app.data(:,:,idx) = h5read(app.FullFileName,dataName);
end
end
else
app.StatusEditField.Value = ‘Not correct type of data file (LBW or HBW)’;
end
end
function updateDataSingleChannel(app,idx)
if app.goodFileSelected
%always update selected channels
getSelectedChannels(app);
if contains(app.SelectedChannels{idx},’None’)
app.data(:,:,idx) = NaN(size(app.Altitude,1),size(app.TimeUT,2));
else
dataName = [‘/CLDSData/’,app.SelectedChannels{idx}];
app.data(:,:,idx) = h5read(app.FullFileName,dataName);
end
else
app.StatusEditField.Value = ‘Not correct type of data file (LBW or HBW)’;
end
end
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
SelectDataFileButtonPushed(app, [])
end
% Button pushed function: QuitButton
function QuitButtonPushed(app, event)
delete(app)
end
% Button pushed function: SelectDataFileButton
function SelectDataFileButtonPushed(app, event)
defname = ‘/Users/Shared/Data/’;
[app.FileName,app.PathName] = uigetfile(‘.h5′,’Select H5 File’,defname);
app.FilenameEditField.Value = app.FileName;
app.PathnameEditField.Value = app.PathName;
app.FullFileName = fullfile(app.PathName,app.FileName);
%get channel names and populate the dropdown lists
%do try catch to see if data file is correct
try
app.ChannelNames = h5read(app.FullFileName,’/Channel_Names’);
selectIdx = contains(app.ChannelNames,’high’);
app.ChannelNames = app.ChannelNames(selectIdx);
app.ChannelNames = [{‘None’};app.ChannelNames];
app.Channel1DropDown.Items = app.ChannelNames;
app.Channel2DropDown.Items = app.ChannelNames;
app.Channel3DropDown.Items = app.ChannelNames;
app.Channel4DropDown.Items = app.ChannelNames;
catch
app.StatusEditField.Value = ‘Not correct type of data file (LBW or HBW)’;
end
%load in the altitude and time data
try
app.Altitude = h5read(app.FullFileName,’/DataProducts/Altitude’)/1000;
app.TimeUT = h5read(app.FullFileName,’/Nav_Data/gps_time’);
app.CurrentRecord = 1;
app.CurrentTimeUT = app.TimeUT(app.CurrentRecord);
app.TimeEditField.Value = app.TimeUT(app.CurrentRecord);
app.RecordEditField.Value = app.CurrentRecord;
app.goodFileSelected = 1;
catch
app.StatusEditField.Value = ‘Issue reading altitude or time from data file’;
end
%get range data
app.range = h5read(app.FullFileName,’/UserInput/range_interp’);
app.range50 = h5read(app.FullFileName,’/UserInput/range50_interp’);
%initialize data array to NaN
app.data = NaN(size(app.Altitude,1),size(app.TimeUT,2),app.NumChannels);
%set limits on record and time values
app.RecordEditField.Limits = [1,size(app.TimeUT,2)];
app.TimeEditField.Limits = [min(app.TimeUT),max(app.TimeUT)];
%update data
updateData(app);
%plot data
updatePlot(app);
end
% Value changed function: RecordEditField
function RecordEditFieldValueChanged(app, event)
value = app.RecordEditField.Value;
app.CurrentRecord = value;
app.TimeEditField.Value = app.TimeUT(app.CurrentRecord);
updatePlot(app)
end
% Value changed function: TimeEditField
function TimeEditFieldValueChanged(app, event)
value = app.TimeEditField.Value;
if value <= app.TimeUT(1,end)
idx = find(app.TimeUT>=value,1,’first’);
else
idx = size(app.TimeUT,2);
end
app.CurrentTimeUT = app.TimeUT(idx);
app.RecordValue.Value = idx;
updatePlot(app)
end
% Value changed function: Channel1DropDown
function Channel1DropDownValueChanged(app, event)
updateDataSingleChannel(app,1);
updatePlot(app);
end
% Value changed function: Channel2DropDown
function Channel2DropDownValueChanged(app, event)
updateDataSingleChannel(app,2);
updatePlot(app);
end
% Value changed function: Channel3DropDown
function Channel3DropDownValueChanged(app, event)
updateDataSingleChannel(app,3);
updatePlot(app);
end
% Value changed function: Channel4DropDown
function Channel4DropDownValueChanged(app, event)
updateDataSingleChannel(app,4);
updatePlot(app);
end
% Value changed function: LogScaleCheckBox
function LogScaleCheckBoxValueChanged(app, event)
updatePlot(app);
end
% Value changed function: LegendCheckBox
function LegendCheckBoxValueChanged(app, event)
updatePlot(app);
end
% Value changed function: CountsMaxEditField
function CountsMaxEditFieldValueChanged(app, event)
updatePlot(app)
end
% Value changed function: CountsMinEditField
function CountsMinEditFieldValueChanged(app, event)
updatePlot(app)
end
% Value changed function: AltMinEditField
function AltMinEditFieldValueChanged(app, event)
updatePlot(app)
end
% Value changed function: AltMaxEditField
function AltMaxEditFieldValueChanged(app, event)
updatePlot(app)
end
% Button pushed function: StepUpButton
function StepUpButtonPushed(app, event)
app.RecordEditField.Value = app.RecordEditField.Value+1;
app.CurrentRecord = app.RecordEditField.Value;
app.TimeEditField.Value = app.TimeUT(app.CurrentRecord);
updatePlot(app)
end
% Button pushed function: StepDownButton
function StepDownButtonPushed(app, event)
app.RecordEditField.Value = app.RecordEditField.Value-1;
app.CurrentRecord = app.RecordEditField.Value;
app.TimeEditField.Value = app.TimeUT(app.CurrentRecord);
updatePlot(app)
end
% Value changed function: RunButton
function RunButtonValueChanged(app, event)
value = app.RunButton.Value;
while value == 1
app.RunButton.Text = ‘Stop’;
app.RunButton.BackgroundColor = [1,0,0];
app.RecordEditField.Value = app.RecordEditField.Value+1;
app.CurrentRecord = app.RecordEditField.Value;
app.TimeEditField.Value = app.TimeUT(app.CurrentRecord);
pause(app.DelaysEditField.Value)
updatePlot(app)
value = app.RunButton.Value;
end
app.RunButton.Text = ‘Run’;
app.RunButton.BackgroundColor = [0.96,0.96,0.96];
end
% Value changed function: Select1064CheckBox
function Select1064CheckBoxValueChanged(app, event)
%uncheck other wavelengths (only one possible)
app.Select532CheckBox.Value = 0;
app.Select355CheckBox.Value = 0;
%set dropdown lists for 1064
app.Channel1DropDown.ValueIndex = 2;
app.Channel2DropDown.ValueIndex = 3;
app.Channel3DropDown.ValueIndex = 1;
app.Channel4DropDown.ValueIndex = 1;
updateData(app);
updatePlot(app)
end
% Value changed function: Select532CheckBox
function Select532CheckBoxValueChanged(app, event)
%uncheck other wavelengths (only one possible)
app.Select1064CheckBox.Value = 0;
app.Select355CheckBox.Value = 0;
%set dropdown lists for 1064
app.Channel1DropDown.ValueIndex = 4;
app.Channel2DropDown.ValueIndex = 5;
app.Channel3DropDown.ValueIndex = 6;
app.Channel4DropDown.ValueIndex = 1;
updateData(app);
updatePlot(app);
end
% Value changed function: Select355CheckBox
function Select355CheckBoxValueChanged(app, event)
%uncheck other wavelengths (only one possible)
app.Select1064CheckBox.Value = 0;
app.Select532CheckBox.Value = 0;
%set dropdown lists for 1064
app.Channel1DropDown.ValueIndex = 7;
app.Channel2DropDown.ValueIndex = 8;
app.Channel3DropDown.ValueIndex = 9;
app.Channel4DropDown.ValueIndex = 10;
updateData(app);
updatePlot(app);
end
% Value changed function: DelaysEditField
function DelaysEditFieldValueChanged(app, event)
value = app.DelaysEditField.Value;
if value < 0.05
app.DelaysEditField.Value = 0.05;
end
end
% Changes arrangement of the app based on UIFigure width
function updateAppLayout(app, event)
currentFigureWidth = app.RawdataPlotterAppUIFigure.Position(3);
if(currentFigureWidth <= app.onePanelWidth)
% Change to a 2×1 grid
app.GridLayout.RowHeight = {642, 642};
app.GridLayout.ColumnWidth = {‘1x’};
app.RightPanel.Layout.Row = 2;
app.RightPanel.Layout.Column = 1;
else
% Change to a 1×2 grid
app.GridLayout.RowHeight = {‘1x’};
app.GridLayout.ColumnWidth = {220, ‘1x’};
app.RightPanel.Layout.Row = 1;
app.RightPanel.Layout.Column = 2;
end
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create RawdataPlotterAppUIFigure and hide until all components are created
app.RawdataPlotterAppUIFigure = uifigure(‘Visible’, ‘off’);
app.RawdataPlotterAppUIFigure.AutoResizeChildren = ‘off’;
app.RawdataPlotterAppUIFigure.Position = [100 100 719 642];
app.RawdataPlotterAppUIFigure.Name = ‘Rawdata Plotter App’;
app.RawdataPlotterAppUIFigure.CloseRequestFcn = createCallbackFcn(app, @delete(gcf), true); %MARKED
app.RawdataPlotterAppUIFigure.SizeChangedFcn = createCallbackFcn(app, @updateAppLayout, true);
% Create GridLayout
app.GridLayout = uigridlayout(app.RawdataPlotterAppUIFigure);
app.GridLayout.ColumnWidth = {220, ‘1x’};
app.GridLayout.RowHeight = {‘1x’};
app.GridLayout.ColumnSpacing = 0;
app.GridLayout.RowSpacing = 0;
app.GridLayout.Padding = [0 0 0 0];
app.GridLayout.Scrollable = ‘on’;
% Create LeftPanel
app.LeftPanel = uipanel(app.GridLayout);
app.LeftPanel.Layout.Row = 1;
app.LeftPanel.Layout.Column = 1;
% Create ChannelSelectPanel
app.ChannelSelectPanel = uipanel(app.LeftPanel);
app.ChannelSelectPanel.Title = ‘Channel Select’;
app.ChannelSelectPanel.Position = [9 132 203 502];
% Create Channel1DropDownLabel
app.Channel1DropDownLabel = uilabel(app.ChannelSelectPanel);
app.Channel1DropDownLabel.HorizontalAlignment = ‘right’;
app.Channel1DropDownLabel.Position = [19 446 59 22];
app.Channel1DropDownLabel.Text = ‘Channel 1’;
% Create Channel1DropDown
app.Channel1DropDown = uidropdown(app.ChannelSelectPanel);
app.Channel1DropDown.ValueChangedFcn = createCallbackFcn(app, @Channel1DropDownValueChanged, true);
app.Channel1DropDown.Position = [93 446 100 22];
% Create Channel2DropDownLabel
app.Channel2DropDownLabel = uilabel(app.ChannelSelectPanel);
app.Channel2DropDownLabel.HorizontalAlignment = ‘right’;
app.Channel2DropDownLabel.Position = [19 412 59 22];
app.Channel2DropDownLabel.Text = ‘Channel 2’;
% Create Channel2DropDown
app.Channel2DropDown = uidropdown(app.ChannelSelectPanel);
app.Channel2DropDown.ValueChangedFcn = createCallbackFcn(app, @Channel2DropDownValueChanged, true);
app.Channel2DropDown.Position = [93 412 100 22];
% Create Channel3DropDownLabel
app.Channel3DropDownLabel = uilabel(app.ChannelSelectPanel);
app.Channel3DropDownLabel.HorizontalAlignment = ‘right’;
app.Channel3DropDownLabel.Position = [19 378 59 22];
app.Channel3DropDownLabel.Text = ‘Channel 3’;
% Create Channel3DropDown
app.Channel3DropDown = uidropdown(app.ChannelSelectPanel);
app.Channel3DropDown.ValueChangedFcn = createCallbackFcn(app, @Channel3DropDownValueChanged, true);
app.Channel3DropDown.Position = [93 378 100 22];
% Create Channel4DropDownLabel
app.Channel4DropDownLabel = uilabel(app.ChannelSelectPanel);
app.Channel4DropDownLabel.HorizontalAlignment = ‘right’;
app.Channel4DropDownLabel.Position = [19 345 59 22];
app.Channel4DropDownLabel.Text = ‘Channel 4’;
% Create Channel4DropDown
app.Channel4DropDown = uidropdown(app.ChannelSelectPanel);
app.Channel4DropDown.ValueChangedFcn = createCallbackFcn(app, @Channel4DropDownValueChanged, true);
app.Channel4DropDown.Position = [93 345 100 22];
% Create TimeEditFieldLabel
app.TimeEditFieldLabel = uilabel(app.ChannelSelectPanel);
app.TimeEditFieldLabel.HorizontalAlignment = ‘right’;
app.TimeEditFieldLabel.Position = [36 210 31 22];
app.TimeEditFieldLabel.Text = ‘Time’;
% Create TimeEditField
app.TimeEditField = uieditfield(app.ChannelSelectPanel, ‘numeric’);
app.TimeEditField.ValueDisplayFormat = ‘%11.6g’;
app.TimeEditField.ValueChangedFcn = createCallbackFcn(app, @TimeEditFieldValueChanged, true);
app.TimeEditField.Position = [77 210 100 22];
% Create RecordEditFieldLabel
app.RecordEditFieldLabel = uilabel(app.ChannelSelectPanel);
app.RecordEditFieldLabel.HorizontalAlignment = ‘right’;
app.RecordEditFieldLabel.Position = [25 185 44 22];
app.RecordEditFieldLabel.Text = ‘Record’;
% Create RecordEditField
app.RecordEditField = uieditfield(app.ChannelSelectPanel, ‘numeric’);
app.RecordEditField.ValueChangedFcn = createCallbackFcn(app, @RecordEditFieldValueChanged, true);
app.RecordEditField.Position = [77 185 100 22];
% Create StepUpButton
app.StepUpButton = uibutton(app.ChannelSelectPanel, ‘push’);
app.StepUpButton.ButtonPushedFcn = createCallbackFcn(app, @StepUpButtonPushed, true);
app.StepUpButton.Position = [109 154 66 23];
app.StepUpButton.Text = ‘Step Up’;
% Create RunButton
app.RunButton = uibutton(app.ChannelSelectPanel, ‘state’);
app.RunButton.ValueChangedFcn = createCallbackFcn(app, @RunButtonValueChanged, true);
app.RunButton.Text = ‘Run’;
app.RunButton.Position = [57 8 60 23];
% Create RangeSquaredCheckBox
app.RangeSquaredCheckBox = uicheckbox(app.ChannelSelectPanel);
app.RangeSquaredCheckBox.Text = ‘Range Squared’;
app.RangeSquaredCheckBox.Position = [9 82 105 22];
% Create LogScaleCheckBox
app.LogScaleCheckBox = uicheckbox(app.ChannelSelectPanel);
app.LogScaleCheckBox.ValueChangedFcn = createCallbackFcn(app, @LogScaleCheckBoxValueChanged, true);
app.LogScaleCheckBox.Text = ‘Log Scale’;
app.LogScaleCheckBox.Position = [9 61 76 22];
app.LogScaleCheckBox.Value = true;
% Create LegendCheckBox
app.LegendCheckBox = uicheckbox(app.ChannelSelectPanel);
app.LegendCheckBox.ValueChangedFcn = createCallbackFcn(app, @LegendCheckBoxValueChanged, true);
app.LegendCheckBox.Text = ‘Legend’;
app.LegendCheckBox.Position = [9 40 62 22];
app.LegendCheckBox.Value = true;
% Create AutoScaleXCheckBox
app.AutoScaleXCheckBox = uicheckbox(app.ChannelSelectPanel);
app.AutoScaleXCheckBox.Text = ‘Auto Scale X’;
app.AutoScaleXCheckBox.Position = [9 123 91 22];
app.AutoScaleXCheckBox.Value = true;
% Create AutoScaleYCheckBox
app.AutoScaleYCheckBox = uicheckbox(app.ChannelSelectPanel);
app.AutoScaleYCheckBox.Text = ‘Auto Scale Y’;
app.AutoScaleYCheckBox.Position = [9 103 91 22];
app.AutoScaleYCheckBox.Value = true;
% Create CountsMinEditFieldLabel
app.CountsMinEditFieldLabel = uilabel(app.ChannelSelectPanel);
app.CountsMinEditFieldLabel.HorizontalAlignment = ‘right’;
app.CountsMinEditFieldLabel.Position = [22 308 67 22];
app.CountsMinEditFieldLabel.Text = ‘Counts Min’;
% Create CountsMinEditField
app.CountsMinEditField = uieditfield(app.ChannelSelectPanel, ‘numeric’);
app.CountsMinEditField.ValueChangedFcn = createCallbackFcn(app, @CountsMinEditFieldValueChanged, true);
app.CountsMinEditField.Position = [25 288 66 22];
app.CountsMinEditField.Value = 0.1;
% Create CountsMaxEditFieldLabel
app.CountsMaxEditFieldLabel = uilabel(app.ChannelSelectPanel);
app.CountsMaxEditFieldLabel.HorizontalAlignment = ‘right’;
app.CountsMaxEditFieldLabel.Position = [104 308 70 22];
app.CountsMaxEditFieldLabel.Text = ‘Counts Max’;
% Create CountsMaxEditField
app.CountsMaxEditField = uieditfield(app.ChannelSelectPanel, ‘numeric’);
app.CountsMaxEditField.ValueChangedFcn = createCallbackFcn(app, @CountsMaxEditFieldValueChanged, true);
app.CountsMaxEditField.Position = [104 288 70 22];
app.CountsMaxEditField.Value = 65536;
% Create AltMinEditFieldLabel
app.AltMinEditFieldLabel = uilabel(app.ChannelSelectPanel);
app.AltMinEditFieldLabel.HorizontalAlignment = ‘right’;
app.AltMinEditFieldLabel.Position = [36 267 42 22];
app.AltMinEditFieldLabel.Text = ‘Alt Min’;
% Create AltMinEditField
app.AltMinEditField = uieditfield(app.ChannelSelectPanel, ‘numeric’);
app.AltMinEditField.ValueChangedFcn = createCallbackFcn(app, @AltMinEditFieldValueChanged, true);
app.AltMinEditField.Position = [25 246 66 22];
app.AltMinEditField.Value = -500;
% Create AltMaxEditFieldLabel
app.AltMaxEditFieldLabel = uilabel(app.ChannelSelectPanel);
app.AltMaxEditFieldLabel.HorizontalAlignment = ‘right’;
app.AltMaxEditFieldLabel.Position = [114 267 46 22];
app.AltMaxEditFieldLabel.Text = ‘Alt Max’;
% Create AltMaxEditField
app.AltMaxEditField = uieditfield(app.ChannelSelectPanel, ‘numeric’);
app.AltMaxEditField.ValueChangedFcn = createCallbackFcn(app, @AltMaxEditFieldValueChanged, true);
app.AltMaxEditField.Position = [104 246 69 22];
app.AltMaxEditField.Value = 22000;
% Create StepDownButton
app.StepDownButton = uibutton(app.ChannelSelectPanel, ‘push’);
app.StepDownButton.ButtonPushedFcn = createCallbackFcn(app, @StepDownButtonPushed, true);
app.StepDownButton.Position = [24 154 75 23];
app.StepDownButton.Text = ‘Step Down’;
% Create DelaysEditFieldLabel
app.DelaysEditFieldLabel = uilabel(app.ChannelSelectPanel);
app.DelaysEditFieldLabel.HorizontalAlignment = ‘right’;
app.DelaysEditFieldLabel.Position = [119 34 51 22];
app.DelaysEditFieldLabel.Text = ‘Delay (s)’;
% Create DelaysEditField
app.DelaysEditField = uieditfield(app.ChannelSelectPanel, ‘numeric’);
app.DelaysEditField.ValueChangedFcn = createCallbackFcn(app, @DelaysEditFieldValueChanged, true);
app.DelaysEditField.Position = [128 9 34 22];
app.DelaysEditField.Value = 1;
% Create Select1064CheckBox
app.Select1064CheckBox = uicheckbox(app.ChannelSelectPanel);
app.Select1064CheckBox.ValueChangedFcn = createCallbackFcn(app, @Select1064CheckBoxValueChanged, true);
app.Select1064CheckBox.Text = ‘Select 1064’;
app.Select1064CheckBox.Position = [119 124 86 22];
% Create Select532CheckBox
app.Select532CheckBox = uicheckbox(app.ChannelSelectPanel);
app.Select532CheckBox.ValueChangedFcn = createCallbackFcn(app, @Select532CheckBoxValueChanged, true);
app.Select532CheckBox.Text = ‘Select 532’;
app.Select532CheckBox.Position = [119 101 79 22];
% Create Select355CheckBox
app.Select355CheckBox = uicheckbox(app.ChannelSelectPanel);
app.Select355CheckBox.ValueChangedFcn = createCallbackFcn(app, @Select355CheckBoxValueChanged, true);
app.Select355CheckBox.Text = ‘Select 355’;
app.Select355CheckBox.Position = [119 79 79 22];
% Create ControlPanel
app.ControlPanel = uipanel(app.LeftPanel);
app.ControlPanel.Title = ‘Control’;
app.ControlPanel.Position = [9 13 203 110];
% Create QuitButton
app.QuitButton = uibutton(app.ControlPanel, ‘push’);
app.QuitButton.ButtonPushedFcn = createCallbackFcn(app, @QuitButtonPushed, true);
app.QuitButton.FontWeight = ‘bold’;
app.QuitButton.FontColor = [1 0 0];
app.QuitButton.Position = [57 12 100 23];
app.QuitButton.Text = ‘Quit’;
% Create SelectDataFileButton
app.SelectDataFileButton = uibutton(app.ControlPanel, ‘push’);
app.SelectDataFileButton.ButtonPushedFcn = createCallbackFcn(app, @SelectDataFileButtonPushed, true);
app.SelectDataFileButton.Position = [57 54 100 23];
app.SelectDataFileButton.Text = ‘Select Data File’;
% Create RightPanel
app.RightPanel = uipanel(app.GridLayout);
app.RightPanel.Layout.Row = 1;
app.RightPanel.Layout.Column = 2;
% Create Panel3
app.Panel3 = uipanel(app.RightPanel);
app.Panel3.Title = ‘Panel3’;
app.Panel3.Position = [9 142 481 493];
% Create UIAxes
app.UIAxes = uiaxes(app.Panel3);
xlabel(app.UIAxes, ‘Counts’)
ylabel(app.UIAxes, ‘Altitude (km)’)
zlabel(app.UIAxes, ‘Z’)
app.UIAxes.GridLineWidth = 0.5;
app.UIAxes.MinorGridLineWidth = 0.5;
app.UIAxes.LineWidth = 0.5;
app.UIAxes.Box = ‘off’;
app.UIAxes.FontSize = 14;
app.UIAxes.Position = [4 0 475 469];
% Create Panel4
app.Panel4 = uipanel(app.RightPanel);
app.Panel4.Title = ‘Panel4’;
app.Panel4.Position = [9 10 479 123];
% Create FilenameEditFieldLabel
app.FilenameEditFieldLabel = uilabel(app.Panel4);
app.FilenameEditFieldLabel.HorizontalAlignment = ‘right’;
app.FilenameEditFieldLabel.Position = [14 75 53 22];
app.FilenameEditFieldLabel.Text = ‘Filename’;
% Create FilenameEditField
app.FilenameEditField = uieditfield(app.Panel4, ‘text’);
app.FilenameEditField.Position = [82 75 388 22];
% Create PathnameEditFieldLabel
app.PathnameEditFieldLabel = uilabel(app.Panel4);
app.PathnameEditFieldLabel.HorizontalAlignment = ‘right’;
app.PathnameEditFieldLabel.Position = [8 47 59 22];
app.PathnameEditFieldLabel.Text = ‘Pathname’;
% Create PathnameEditField
app.PathnameEditField = uieditfield(app.Panel4, ‘text’);
app.PathnameEditField.Position = [82 47 388 22];
% Create StatusEditFieldLabel
app.StatusEditFieldLabel = uilabel(app.Panel4);
app.StatusEditFieldLabel.HorizontalAlignment = ‘right’;
app.StatusEditFieldLabel.Position = [28 19 39 22];
app.StatusEditFieldLabel.Text = ‘Status’;
% Create StatusEditField
app.StatusEditField = uieditfield(app.Panel4, ‘text’);
app.StatusEditField.Position = [82 19 388 22];
% Show the figure after all components are created
app.RawdataPlotterAppUIFigure.Visible = ‘on’;
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = RawDataPlotterNew
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.RawdataPlotterAppUIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.RawdataPlotterAppUIFigure)
end
end
end App designer places code (grayed out) that shows an error. I will note that the code ran fine before I saved and closed it out and then later restarted the app. I think the issue might be related to the fact that I had a callback that used the delete function which is used to close the app.
The line that show the syntax error is the following and bold in the full code listing:
app.RawdataPlotterAppUIFigure.CloseRequestFcn = createCallbackFcn(app, @delete(gcf), true);
Full code below:
classdef RawDataPlotterNew < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
RawdataPlotterAppUIFigure matlab.ui.Figure
GridLayout matlab.ui.container.GridLayout
LeftPanel matlab.ui.container.Panel
ControlPanel matlab.ui.container.Panel
SelectDataFileButton matlab.ui.control.Button
QuitButton matlab.ui.control.Button
ChannelSelectPanel matlab.ui.container.Panel
Select355CheckBox matlab.ui.control.CheckBox
Select532CheckBox matlab.ui.control.CheckBox
Select1064CheckBox matlab.ui.control.CheckBox
DelaysEditField matlab.ui.control.NumericEditField
DelaysEditFieldLabel matlab.ui.control.Label
StepDownButton matlab.ui.control.Button
AltMaxEditField matlab.ui.control.NumericEditField
AltMaxEditFieldLabel matlab.ui.control.Label
AltMinEditField matlab.ui.control.NumericEditField
AltMinEditFieldLabel matlab.ui.control.Label
CountsMaxEditField matlab.ui.control.NumericEditField
CountsMaxEditFieldLabel matlab.ui.control.Label
CountsMinEditField matlab.ui.control.NumericEditField
CountsMinEditFieldLabel matlab.ui.control.Label
AutoScaleYCheckBox matlab.ui.control.CheckBox
AutoScaleXCheckBox matlab.ui.control.CheckBox
LegendCheckBox matlab.ui.control.CheckBox
LogScaleCheckBox matlab.ui.control.CheckBox
RangeSquaredCheckBox matlab.ui.control.CheckBox
RunButton matlab.ui.control.StateButton
StepUpButton matlab.ui.control.Button
RecordEditField matlab.ui.control.NumericEditField
RecordEditFieldLabel matlab.ui.control.Label
TimeEditField matlab.ui.control.NumericEditField
TimeEditFieldLabel matlab.ui.control.Label
Channel4DropDown matlab.ui.control.DropDown
Channel4DropDownLabel matlab.ui.control.Label
Channel3DropDown matlab.ui.control.DropDown
Channel3DropDownLabel matlab.ui.control.Label
Channel2DropDown matlab.ui.control.DropDown
Channel2DropDownLabel matlab.ui.control.Label
Channel1DropDown matlab.ui.control.DropDown
Channel1DropDownLabel matlab.ui.control.Label
RightPanel matlab.ui.container.Panel
Panel4 matlab.ui.container.Panel
StatusEditField matlab.ui.control.EditField
StatusEditFieldLabel matlab.ui.control.Label
PathnameEditField matlab.ui.control.EditField
PathnameEditFieldLabel matlab.ui.control.Label
FilenameEditField matlab.ui.control.EditField
FilenameEditFieldLabel matlab.ui.control.Label
Panel3 matlab.ui.container.Panel
UIAxes matlab.ui.control.UIAxes
end
% Properties that correspond to apps with auto-reflow
properties (Access = private)
onePanelWidth = 576;
end
properties (Access = private)
FileName; % File for rawdata file being plotted
PathName; % Path for rawdata file being plotted
FullFileName; %Full filename
ChannelNames; %Names of the channels in data file
Altitude; %Altitude from raw data file
TimeUT; %time from rawdata file
SelectedChannels; %array of selected channels
CurrentRecord; %record index
CurrentTimeUT; %current time of data record
data; % data from selected channels
range; % range data for all PMT channels
range50; % range data for all APD channels
NumChannels = 4;
goodFileSelected = 0; %toggle to make sure a good file is selected
end
methods (Access = private)
function updatePlot(app)
getSelectedChannels(app)
for idx=1:app.NumChannels
if app.RangeSquaredCheckBox.Value
x = squeeze(app.data(:,app.CurrentRecord,idx));
else
if contains(app.SelectedChannels(idx),’1064′)
x = squeeze(app.data(:,app.CurrentRecord,idx))./(app.range50(:,app.CurrentRecord)).^2;
else
x = squeeze(app.data(:,app.CurrentRecord,idx))./(app.range(:,app.CurrentRecord)).^2;
end
end
plot(app.UIAxes,x,app.Altitude);
hold(app.UIAxes,’on’)
end
hold(app.UIAxes,’off’)
%scale axes
if app.AutoScaleXCheckBox.Value
xlim(app.UIAxes,[0,2^16]);
else
xlim(app.UIAxes, [app.CountsMinEditField.Value,app.CountsMaxEditField.Value]);
end
if app.AutoScaleYCheckBox.Value
ylim(app.UIAxes, [min(app.Altitude),max(app.Altitude)]);
else
ylim(app.UIAxes, [app.AltMinEditField.Value,app.AltMaxEditField.Value]);
end
%check log scale
if app.LogScaleCheckBox.Value == 1
xscale(app.UIAxes,"log");
else
xscale(app.UIAxes,"linear");
end
%add legend
if app.LegendCheckBox.Value
legend(app.UIAxes,app.SelectedChannels,’Interpreter’, ‘none’)
else
legend(app.UIAxes,’off’)
end
drawnow;
end
function getSelectedChannels(app)
channel(1) = app.Channel1DropDown.ValueIndex;
channel(2) = app.Channel2DropDown.ValueIndex;
channel(3) = app.Channel3DropDown.ValueIndex;
channel(4) = app.Channel4DropDown.ValueIndex;
for idx=1:app.NumChannels
app.SelectedChannels{idx} = app.ChannelNames{channel(idx)};
end
end
function updateData(app)
if app.goodFileSelected
%always update selected channels
getSelectedChannels(app);
for idx=1:app.NumChannels
if contains(app.SelectedChannels{idx},’None’)
app.data(:,:,idx) = NaN(size(app.Altitude,1),size(app.TimeUT,2));
else
dataName = [‘/CLDSData/’,app.SelectedChannels{idx}];
app.data(:,:,idx) = h5read(app.FullFileName,dataName);
end
end
else
app.StatusEditField.Value = ‘Not correct type of data file (LBW or HBW)’;
end
end
function updateDataSingleChannel(app,idx)
if app.goodFileSelected
%always update selected channels
getSelectedChannels(app);
if contains(app.SelectedChannels{idx},’None’)
app.data(:,:,idx) = NaN(size(app.Altitude,1),size(app.TimeUT,2));
else
dataName = [‘/CLDSData/’,app.SelectedChannels{idx}];
app.data(:,:,idx) = h5read(app.FullFileName,dataName);
end
else
app.StatusEditField.Value = ‘Not correct type of data file (LBW or HBW)’;
end
end
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
SelectDataFileButtonPushed(app, [])
end
% Button pushed function: QuitButton
function QuitButtonPushed(app, event)
delete(app)
end
% Button pushed function: SelectDataFileButton
function SelectDataFileButtonPushed(app, event)
defname = ‘/Users/Shared/Data/’;
[app.FileName,app.PathName] = uigetfile(‘.h5′,’Select H5 File’,defname);
app.FilenameEditField.Value = app.FileName;
app.PathnameEditField.Value = app.PathName;
app.FullFileName = fullfile(app.PathName,app.FileName);
%get channel names and populate the dropdown lists
%do try catch to see if data file is correct
try
app.ChannelNames = h5read(app.FullFileName,’/Channel_Names’);
selectIdx = contains(app.ChannelNames,’high’);
app.ChannelNames = app.ChannelNames(selectIdx);
app.ChannelNames = [{‘None’};app.ChannelNames];
app.Channel1DropDown.Items = app.ChannelNames;
app.Channel2DropDown.Items = app.ChannelNames;
app.Channel3DropDown.Items = app.ChannelNames;
app.Channel4DropDown.Items = app.ChannelNames;
catch
app.StatusEditField.Value = ‘Not correct type of data file (LBW or HBW)’;
end
%load in the altitude and time data
try
app.Altitude = h5read(app.FullFileName,’/DataProducts/Altitude’)/1000;
app.TimeUT = h5read(app.FullFileName,’/Nav_Data/gps_time’);
app.CurrentRecord = 1;
app.CurrentTimeUT = app.TimeUT(app.CurrentRecord);
app.TimeEditField.Value = app.TimeUT(app.CurrentRecord);
app.RecordEditField.Value = app.CurrentRecord;
app.goodFileSelected = 1;
catch
app.StatusEditField.Value = ‘Issue reading altitude or time from data file’;
end
%get range data
app.range = h5read(app.FullFileName,’/UserInput/range_interp’);
app.range50 = h5read(app.FullFileName,’/UserInput/range50_interp’);
%initialize data array to NaN
app.data = NaN(size(app.Altitude,1),size(app.TimeUT,2),app.NumChannels);
%set limits on record and time values
app.RecordEditField.Limits = [1,size(app.TimeUT,2)];
app.TimeEditField.Limits = [min(app.TimeUT),max(app.TimeUT)];
%update data
updateData(app);
%plot data
updatePlot(app);
end
% Value changed function: RecordEditField
function RecordEditFieldValueChanged(app, event)
value = app.RecordEditField.Value;
app.CurrentRecord = value;
app.TimeEditField.Value = app.TimeUT(app.CurrentRecord);
updatePlot(app)
end
% Value changed function: TimeEditField
function TimeEditFieldValueChanged(app, event)
value = app.TimeEditField.Value;
if value <= app.TimeUT(1,end)
idx = find(app.TimeUT>=value,1,’first’);
else
idx = size(app.TimeUT,2);
end
app.CurrentTimeUT = app.TimeUT(idx);
app.RecordValue.Value = idx;
updatePlot(app)
end
% Value changed function: Channel1DropDown
function Channel1DropDownValueChanged(app, event)
updateDataSingleChannel(app,1);
updatePlot(app);
end
% Value changed function: Channel2DropDown
function Channel2DropDownValueChanged(app, event)
updateDataSingleChannel(app,2);
updatePlot(app);
end
% Value changed function: Channel3DropDown
function Channel3DropDownValueChanged(app, event)
updateDataSingleChannel(app,3);
updatePlot(app);
end
% Value changed function: Channel4DropDown
function Channel4DropDownValueChanged(app, event)
updateDataSingleChannel(app,4);
updatePlot(app);
end
% Value changed function: LogScaleCheckBox
function LogScaleCheckBoxValueChanged(app, event)
updatePlot(app);
end
% Value changed function: LegendCheckBox
function LegendCheckBoxValueChanged(app, event)
updatePlot(app);
end
% Value changed function: CountsMaxEditField
function CountsMaxEditFieldValueChanged(app, event)
updatePlot(app)
end
% Value changed function: CountsMinEditField
function CountsMinEditFieldValueChanged(app, event)
updatePlot(app)
end
% Value changed function: AltMinEditField
function AltMinEditFieldValueChanged(app, event)
updatePlot(app)
end
% Value changed function: AltMaxEditField
function AltMaxEditFieldValueChanged(app, event)
updatePlot(app)
end
% Button pushed function: StepUpButton
function StepUpButtonPushed(app, event)
app.RecordEditField.Value = app.RecordEditField.Value+1;
app.CurrentRecord = app.RecordEditField.Value;
app.TimeEditField.Value = app.TimeUT(app.CurrentRecord);
updatePlot(app)
end
% Button pushed function: StepDownButton
function StepDownButtonPushed(app, event)
app.RecordEditField.Value = app.RecordEditField.Value-1;
app.CurrentRecord = app.RecordEditField.Value;
app.TimeEditField.Value = app.TimeUT(app.CurrentRecord);
updatePlot(app)
end
% Value changed function: RunButton
function RunButtonValueChanged(app, event)
value = app.RunButton.Value;
while value == 1
app.RunButton.Text = ‘Stop’;
app.RunButton.BackgroundColor = [1,0,0];
app.RecordEditField.Value = app.RecordEditField.Value+1;
app.CurrentRecord = app.RecordEditField.Value;
app.TimeEditField.Value = app.TimeUT(app.CurrentRecord);
pause(app.DelaysEditField.Value)
updatePlot(app)
value = app.RunButton.Value;
end
app.RunButton.Text = ‘Run’;
app.RunButton.BackgroundColor = [0.96,0.96,0.96];
end
% Value changed function: Select1064CheckBox
function Select1064CheckBoxValueChanged(app, event)
%uncheck other wavelengths (only one possible)
app.Select532CheckBox.Value = 0;
app.Select355CheckBox.Value = 0;
%set dropdown lists for 1064
app.Channel1DropDown.ValueIndex = 2;
app.Channel2DropDown.ValueIndex = 3;
app.Channel3DropDown.ValueIndex = 1;
app.Channel4DropDown.ValueIndex = 1;
updateData(app);
updatePlot(app)
end
% Value changed function: Select532CheckBox
function Select532CheckBoxValueChanged(app, event)
%uncheck other wavelengths (only one possible)
app.Select1064CheckBox.Value = 0;
app.Select355CheckBox.Value = 0;
%set dropdown lists for 1064
app.Channel1DropDown.ValueIndex = 4;
app.Channel2DropDown.ValueIndex = 5;
app.Channel3DropDown.ValueIndex = 6;
app.Channel4DropDown.ValueIndex = 1;
updateData(app);
updatePlot(app);
end
% Value changed function: Select355CheckBox
function Select355CheckBoxValueChanged(app, event)
%uncheck other wavelengths (only one possible)
app.Select1064CheckBox.Value = 0;
app.Select532CheckBox.Value = 0;
%set dropdown lists for 1064
app.Channel1DropDown.ValueIndex = 7;
app.Channel2DropDown.ValueIndex = 8;
app.Channel3DropDown.ValueIndex = 9;
app.Channel4DropDown.ValueIndex = 10;
updateData(app);
updatePlot(app);
end
% Value changed function: DelaysEditField
function DelaysEditFieldValueChanged(app, event)
value = app.DelaysEditField.Value;
if value < 0.05
app.DelaysEditField.Value = 0.05;
end
end
% Changes arrangement of the app based on UIFigure width
function updateAppLayout(app, event)
currentFigureWidth = app.RawdataPlotterAppUIFigure.Position(3);
if(currentFigureWidth <= app.onePanelWidth)
% Change to a 2×1 grid
app.GridLayout.RowHeight = {642, 642};
app.GridLayout.ColumnWidth = {‘1x’};
app.RightPanel.Layout.Row = 2;
app.RightPanel.Layout.Column = 1;
else
% Change to a 1×2 grid
app.GridLayout.RowHeight = {‘1x’};
app.GridLayout.ColumnWidth = {220, ‘1x’};
app.RightPanel.Layout.Row = 1;
app.RightPanel.Layout.Column = 2;
end
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create RawdataPlotterAppUIFigure and hide until all components are created
app.RawdataPlotterAppUIFigure = uifigure(‘Visible’, ‘off’);
app.RawdataPlotterAppUIFigure.AutoResizeChildren = ‘off’;
app.RawdataPlotterAppUIFigure.Position = [100 100 719 642];
app.RawdataPlotterAppUIFigure.Name = ‘Rawdata Plotter App’;
app.RawdataPlotterAppUIFigure.CloseRequestFcn = createCallbackFcn(app, @delete(gcf), true); %MARKED
app.RawdataPlotterAppUIFigure.SizeChangedFcn = createCallbackFcn(app, @updateAppLayout, true);
% Create GridLayout
app.GridLayout = uigridlayout(app.RawdataPlotterAppUIFigure);
app.GridLayout.ColumnWidth = {220, ‘1x’};
app.GridLayout.RowHeight = {‘1x’};
app.GridLayout.ColumnSpacing = 0;
app.GridLayout.RowSpacing = 0;
app.GridLayout.Padding = [0 0 0 0];
app.GridLayout.Scrollable = ‘on’;
% Create LeftPanel
app.LeftPanel = uipanel(app.GridLayout);
app.LeftPanel.Layout.Row = 1;
app.LeftPanel.Layout.Column = 1;
% Create ChannelSelectPanel
app.ChannelSelectPanel = uipanel(app.LeftPanel);
app.ChannelSelectPanel.Title = ‘Channel Select’;
app.ChannelSelectPanel.Position = [9 132 203 502];
% Create Channel1DropDownLabel
app.Channel1DropDownLabel = uilabel(app.ChannelSelectPanel);
app.Channel1DropDownLabel.HorizontalAlignment = ‘right’;
app.Channel1DropDownLabel.Position = [19 446 59 22];
app.Channel1DropDownLabel.Text = ‘Channel 1’;
% Create Channel1DropDown
app.Channel1DropDown = uidropdown(app.ChannelSelectPanel);
app.Channel1DropDown.ValueChangedFcn = createCallbackFcn(app, @Channel1DropDownValueChanged, true);
app.Channel1DropDown.Position = [93 446 100 22];
% Create Channel2DropDownLabel
app.Channel2DropDownLabel = uilabel(app.ChannelSelectPanel);
app.Channel2DropDownLabel.HorizontalAlignment = ‘right’;
app.Channel2DropDownLabel.Position = [19 412 59 22];
app.Channel2DropDownLabel.Text = ‘Channel 2’;
% Create Channel2DropDown
app.Channel2DropDown = uidropdown(app.ChannelSelectPanel);
app.Channel2DropDown.ValueChangedFcn = createCallbackFcn(app, @Channel2DropDownValueChanged, true);
app.Channel2DropDown.Position = [93 412 100 22];
% Create Channel3DropDownLabel
app.Channel3DropDownLabel = uilabel(app.ChannelSelectPanel);
app.Channel3DropDownLabel.HorizontalAlignment = ‘right’;
app.Channel3DropDownLabel.Position = [19 378 59 22];
app.Channel3DropDownLabel.Text = ‘Channel 3’;
% Create Channel3DropDown
app.Channel3DropDown = uidropdown(app.ChannelSelectPanel);
app.Channel3DropDown.ValueChangedFcn = createCallbackFcn(app, @Channel3DropDownValueChanged, true);
app.Channel3DropDown.Position = [93 378 100 22];
% Create Channel4DropDownLabel
app.Channel4DropDownLabel = uilabel(app.ChannelSelectPanel);
app.Channel4DropDownLabel.HorizontalAlignment = ‘right’;
app.Channel4DropDownLabel.Position = [19 345 59 22];
app.Channel4DropDownLabel.Text = ‘Channel 4’;
% Create Channel4DropDown
app.Channel4DropDown = uidropdown(app.ChannelSelectPanel);
app.Channel4DropDown.ValueChangedFcn = createCallbackFcn(app, @Channel4DropDownValueChanged, true);
app.Channel4DropDown.Position = [93 345 100 22];
% Create TimeEditFieldLabel
app.TimeEditFieldLabel = uilabel(app.ChannelSelectPanel);
app.TimeEditFieldLabel.HorizontalAlignment = ‘right’;
app.TimeEditFieldLabel.Position = [36 210 31 22];
app.TimeEditFieldLabel.Text = ‘Time’;
% Create TimeEditField
app.TimeEditField = uieditfield(app.ChannelSelectPanel, ‘numeric’);
app.TimeEditField.ValueDisplayFormat = ‘%11.6g’;
app.TimeEditField.ValueChangedFcn = createCallbackFcn(app, @TimeEditFieldValueChanged, true);
app.TimeEditField.Position = [77 210 100 22];
% Create RecordEditFieldLabel
app.RecordEditFieldLabel = uilabel(app.ChannelSelectPanel);
app.RecordEditFieldLabel.HorizontalAlignment = ‘right’;
app.RecordEditFieldLabel.Position = [25 185 44 22];
app.RecordEditFieldLabel.Text = ‘Record’;
% Create RecordEditField
app.RecordEditField = uieditfield(app.ChannelSelectPanel, ‘numeric’);
app.RecordEditField.ValueChangedFcn = createCallbackFcn(app, @RecordEditFieldValueChanged, true);
app.RecordEditField.Position = [77 185 100 22];
% Create StepUpButton
app.StepUpButton = uibutton(app.ChannelSelectPanel, ‘push’);
app.StepUpButton.ButtonPushedFcn = createCallbackFcn(app, @StepUpButtonPushed, true);
app.StepUpButton.Position = [109 154 66 23];
app.StepUpButton.Text = ‘Step Up’;
% Create RunButton
app.RunButton = uibutton(app.ChannelSelectPanel, ‘state’);
app.RunButton.ValueChangedFcn = createCallbackFcn(app, @RunButtonValueChanged, true);
app.RunButton.Text = ‘Run’;
app.RunButton.Position = [57 8 60 23];
% Create RangeSquaredCheckBox
app.RangeSquaredCheckBox = uicheckbox(app.ChannelSelectPanel);
app.RangeSquaredCheckBox.Text = ‘Range Squared’;
app.RangeSquaredCheckBox.Position = [9 82 105 22];
% Create LogScaleCheckBox
app.LogScaleCheckBox = uicheckbox(app.ChannelSelectPanel);
app.LogScaleCheckBox.ValueChangedFcn = createCallbackFcn(app, @LogScaleCheckBoxValueChanged, true);
app.LogScaleCheckBox.Text = ‘Log Scale’;
app.LogScaleCheckBox.Position = [9 61 76 22];
app.LogScaleCheckBox.Value = true;
% Create LegendCheckBox
app.LegendCheckBox = uicheckbox(app.ChannelSelectPanel);
app.LegendCheckBox.ValueChangedFcn = createCallbackFcn(app, @LegendCheckBoxValueChanged, true);
app.LegendCheckBox.Text = ‘Legend’;
app.LegendCheckBox.Position = [9 40 62 22];
app.LegendCheckBox.Value = true;
% Create AutoScaleXCheckBox
app.AutoScaleXCheckBox = uicheckbox(app.ChannelSelectPanel);
app.AutoScaleXCheckBox.Text = ‘Auto Scale X’;
app.AutoScaleXCheckBox.Position = [9 123 91 22];
app.AutoScaleXCheckBox.Value = true;
% Create AutoScaleYCheckBox
app.AutoScaleYCheckBox = uicheckbox(app.ChannelSelectPanel);
app.AutoScaleYCheckBox.Text = ‘Auto Scale Y’;
app.AutoScaleYCheckBox.Position = [9 103 91 22];
app.AutoScaleYCheckBox.Value = true;
% Create CountsMinEditFieldLabel
app.CountsMinEditFieldLabel = uilabel(app.ChannelSelectPanel);
app.CountsMinEditFieldLabel.HorizontalAlignment = ‘right’;
app.CountsMinEditFieldLabel.Position = [22 308 67 22];
app.CountsMinEditFieldLabel.Text = ‘Counts Min’;
% Create CountsMinEditField
app.CountsMinEditField = uieditfield(app.ChannelSelectPanel, ‘numeric’);
app.CountsMinEditField.ValueChangedFcn = createCallbackFcn(app, @CountsMinEditFieldValueChanged, true);
app.CountsMinEditField.Position = [25 288 66 22];
app.CountsMinEditField.Value = 0.1;
% Create CountsMaxEditFieldLabel
app.CountsMaxEditFieldLabel = uilabel(app.ChannelSelectPanel);
app.CountsMaxEditFieldLabel.HorizontalAlignment = ‘right’;
app.CountsMaxEditFieldLabel.Position = [104 308 70 22];
app.CountsMaxEditFieldLabel.Text = ‘Counts Max’;
% Create CountsMaxEditField
app.CountsMaxEditField = uieditfield(app.ChannelSelectPanel, ‘numeric’);
app.CountsMaxEditField.ValueChangedFcn = createCallbackFcn(app, @CountsMaxEditFieldValueChanged, true);
app.CountsMaxEditField.Position = [104 288 70 22];
app.CountsMaxEditField.Value = 65536;
% Create AltMinEditFieldLabel
app.AltMinEditFieldLabel = uilabel(app.ChannelSelectPanel);
app.AltMinEditFieldLabel.HorizontalAlignment = ‘right’;
app.AltMinEditFieldLabel.Position = [36 267 42 22];
app.AltMinEditFieldLabel.Text = ‘Alt Min’;
% Create AltMinEditField
app.AltMinEditField = uieditfield(app.ChannelSelectPanel, ‘numeric’);
app.AltMinEditField.ValueChangedFcn = createCallbackFcn(app, @AltMinEditFieldValueChanged, true);
app.AltMinEditField.Position = [25 246 66 22];
app.AltMinEditField.Value = -500;
% Create AltMaxEditFieldLabel
app.AltMaxEditFieldLabel = uilabel(app.ChannelSelectPanel);
app.AltMaxEditFieldLabel.HorizontalAlignment = ‘right’;
app.AltMaxEditFieldLabel.Position = [114 267 46 22];
app.AltMaxEditFieldLabel.Text = ‘Alt Max’;
% Create AltMaxEditField
app.AltMaxEditField = uieditfield(app.ChannelSelectPanel, ‘numeric’);
app.AltMaxEditField.ValueChangedFcn = createCallbackFcn(app, @AltMaxEditFieldValueChanged, true);
app.AltMaxEditField.Position = [104 246 69 22];
app.AltMaxEditField.Value = 22000;
% Create StepDownButton
app.StepDownButton = uibutton(app.ChannelSelectPanel, ‘push’);
app.StepDownButton.ButtonPushedFcn = createCallbackFcn(app, @StepDownButtonPushed, true);
app.StepDownButton.Position = [24 154 75 23];
app.StepDownButton.Text = ‘Step Down’;
% Create DelaysEditFieldLabel
app.DelaysEditFieldLabel = uilabel(app.ChannelSelectPanel);
app.DelaysEditFieldLabel.HorizontalAlignment = ‘right’;
app.DelaysEditFieldLabel.Position = [119 34 51 22];
app.DelaysEditFieldLabel.Text = ‘Delay (s)’;
% Create DelaysEditField
app.DelaysEditField = uieditfield(app.ChannelSelectPanel, ‘numeric’);
app.DelaysEditField.ValueChangedFcn = createCallbackFcn(app, @DelaysEditFieldValueChanged, true);
app.DelaysEditField.Position = [128 9 34 22];
app.DelaysEditField.Value = 1;
% Create Select1064CheckBox
app.Select1064CheckBox = uicheckbox(app.ChannelSelectPanel);
app.Select1064CheckBox.ValueChangedFcn = createCallbackFcn(app, @Select1064CheckBoxValueChanged, true);
app.Select1064CheckBox.Text = ‘Select 1064’;
app.Select1064CheckBox.Position = [119 124 86 22];
% Create Select532CheckBox
app.Select532CheckBox = uicheckbox(app.ChannelSelectPanel);
app.Select532CheckBox.ValueChangedFcn = createCallbackFcn(app, @Select532CheckBoxValueChanged, true);
app.Select532CheckBox.Text = ‘Select 532’;
app.Select532CheckBox.Position = [119 101 79 22];
% Create Select355CheckBox
app.Select355CheckBox = uicheckbox(app.ChannelSelectPanel);
app.Select355CheckBox.ValueChangedFcn = createCallbackFcn(app, @Select355CheckBoxValueChanged, true);
app.Select355CheckBox.Text = ‘Select 355’;
app.Select355CheckBox.Position = [119 79 79 22];
% Create ControlPanel
app.ControlPanel = uipanel(app.LeftPanel);
app.ControlPanel.Title = ‘Control’;
app.ControlPanel.Position = [9 13 203 110];
% Create QuitButton
app.QuitButton = uibutton(app.ControlPanel, ‘push’);
app.QuitButton.ButtonPushedFcn = createCallbackFcn(app, @QuitButtonPushed, true);
app.QuitButton.FontWeight = ‘bold’;
app.QuitButton.FontColor = [1 0 0];
app.QuitButton.Position = [57 12 100 23];
app.QuitButton.Text = ‘Quit’;
% Create SelectDataFileButton
app.SelectDataFileButton = uibutton(app.ControlPanel, ‘push’);
app.SelectDataFileButton.ButtonPushedFcn = createCallbackFcn(app, @SelectDataFileButtonPushed, true);
app.SelectDataFileButton.Position = [57 54 100 23];
app.SelectDataFileButton.Text = ‘Select Data File’;
% Create RightPanel
app.RightPanel = uipanel(app.GridLayout);
app.RightPanel.Layout.Row = 1;
app.RightPanel.Layout.Column = 2;
% Create Panel3
app.Panel3 = uipanel(app.RightPanel);
app.Panel3.Title = ‘Panel3’;
app.Panel3.Position = [9 142 481 493];
% Create UIAxes
app.UIAxes = uiaxes(app.Panel3);
xlabel(app.UIAxes, ‘Counts’)
ylabel(app.UIAxes, ‘Altitude (km)’)
zlabel(app.UIAxes, ‘Z’)
app.UIAxes.GridLineWidth = 0.5;
app.UIAxes.MinorGridLineWidth = 0.5;
app.UIAxes.LineWidth = 0.5;
app.UIAxes.Box = ‘off’;
app.UIAxes.FontSize = 14;
app.UIAxes.Position = [4 0 475 469];
% Create Panel4
app.Panel4 = uipanel(app.RightPanel);
app.Panel4.Title = ‘Panel4’;
app.Panel4.Position = [9 10 479 123];
% Create FilenameEditFieldLabel
app.FilenameEditFieldLabel = uilabel(app.Panel4);
app.FilenameEditFieldLabel.HorizontalAlignment = ‘right’;
app.FilenameEditFieldLabel.Position = [14 75 53 22];
app.FilenameEditFieldLabel.Text = ‘Filename’;
% Create FilenameEditField
app.FilenameEditField = uieditfield(app.Panel4, ‘text’);
app.FilenameEditField.Position = [82 75 388 22];
% Create PathnameEditFieldLabel
app.PathnameEditFieldLabel = uilabel(app.Panel4);
app.PathnameEditFieldLabel.HorizontalAlignment = ‘right’;
app.PathnameEditFieldLabel.Position = [8 47 59 22];
app.PathnameEditFieldLabel.Text = ‘Pathname’;
% Create PathnameEditField
app.PathnameEditField = uieditfield(app.Panel4, ‘text’);
app.PathnameEditField.Position = [82 47 388 22];
% Create StatusEditFieldLabel
app.StatusEditFieldLabel = uilabel(app.Panel4);
app.StatusEditFieldLabel.HorizontalAlignment = ‘right’;
app.StatusEditFieldLabel.Position = [28 19 39 22];
app.StatusEditFieldLabel.Text = ‘Status’;
% Create StatusEditField
app.StatusEditField = uieditfield(app.Panel4, ‘text’);
app.StatusEditField.Position = [82 19 388 22];
% Show the figure after all components are created
app.RawdataPlotterAppUIFigure.Visible = ‘on’;
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = RawDataPlotterNew
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.RawdataPlotterAppUIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.RawdataPlotterAppUIFigure)
end
end
end app designer, generated code, syntax error MATLAB Answers — New Questions
OCR (optical character recognition) misreading simple numbers even when image is pre-processed. What’s the issue?
I followed the advice in this ( https://www.mathworks.com/matlabcentral/answers/1955379-ocr-not-recognizing-some-numbers ) forum to pre-process a series of images but my code is still outputting terribly inaccurate results. I make sure to draw the ROI just around the "0.12" and it does not help. Here’s my code and one image:
clc; clear all
I = imread(‘test.jpg’);
I_gray = rgb2gray(I);
I_gray_binary = imbinarize(I_gray);
I_f = medfilt2(I_gray_binary);
[J,roi] = imcrop(I_f);
ocrResults = ocr(I_f,roi,Language=’seven-segment’);
ocrResults.Text
Thanks to anyone who can offer any advice!I followed the advice in this ( https://www.mathworks.com/matlabcentral/answers/1955379-ocr-not-recognizing-some-numbers ) forum to pre-process a series of images but my code is still outputting terribly inaccurate results. I make sure to draw the ROI just around the "0.12" and it does not help. Here’s my code and one image:
clc; clear all
I = imread(‘test.jpg’);
I_gray = rgb2gray(I);
I_gray_binary = imbinarize(I_gray);
I_f = medfilt2(I_gray_binary);
[J,roi] = imcrop(I_f);
ocrResults = ocr(I_f,roi,Language=’seven-segment’);
ocrResults.Text
Thanks to anyone who can offer any advice! I followed the advice in this ( https://www.mathworks.com/matlabcentral/answers/1955379-ocr-not-recognizing-some-numbers ) forum to pre-process a series of images but my code is still outputting terribly inaccurate results. I make sure to draw the ROI just around the "0.12" and it does not help. Here’s my code and one image:
clc; clear all
I = imread(‘test.jpg’);
I_gray = rgb2gray(I);
I_gray_binary = imbinarize(I_gray);
I_f = medfilt2(I_gray_binary);
[J,roi] = imcrop(I_f);
ocrResults = ocr(I_f,roi,Language=’seven-segment’);
ocrResults.Text
Thanks to anyone who can offer any advice! image processing, ocr, computer vision MATLAB Answers — New Questions
Actiate licence with email as requested
My college has a MATLAB licence, how do I link to that licence?
Some computers are running MATLAB.My college has a MATLAB licence, how do I link to that licence?
Some computers are running MATLAB. My college has a MATLAB licence, how do I link to that licence?
Some computers are running MATLAB. matlab simulink control MATLAB Answers — New Questions
vpasolve giving incorrect answers for a system of trigonometric equations. Where’s the error??
I’m trying to use vpasolve to solve a system of trigonomic equations. Known variables are Sa1, Sa2, and Sa3. Unknown variables are S, AR, PHI. The code hasn’t been giving me the correct results, but I can’t figure out where the error is.
Can someone with sharper eyes spot the problem?
I assigned fake values for the unknown variables, so I could calculate known variable values to test.
%locations of observation points
x1 = -9.72; y1 = -5.62; %OBS4
x2 = -4.95; y2 = -5.60; %OBS5
x3 = 6.63; y3 = -3.76; %OBS6
%assign fake values to unknown variables
S = 3.4e-5; AR = 10; PHI = 36;
%interim variables
W1 = ((-x1*sind(PHI) + y1*cosd(PHI)) / (y1*sind(PHI) + x1*cosd(PHI)));
W2 = ((-x2*sind(PHI) + y2*cosd(PHI)) / (y2*sind(PHI) + x2*cosd(PHI)));
W3 = ((-x3*sind(PHI) + y3*cosd(PHI)) / (y3*sind(PHI) + x3*cosd(PHI)));
%calculate known variable values to test
Sa1 = S*(sqrt(AR^-1)*(cosd(W1))^2+sqrt(AR)*(sind(W1))^2)
Sa2 = S*(sqrt(AR^-1)*(cosd(W2))^2+sqrt(AR)*(sind(W2))^2)
Sa3 = S*(sqrt(AR^-1)*(cosd(W3))^2+sqrt(AR)*(sind(W3))^2)
The above returns Sa1 = 1.0752e-05, Sa2 = 1.0753e-05, and Sa3 = 1.0894e-05.
Having created known variable values with my fake unknown variable values, I’m not able to return the numbers I assigned. The code below is what I’m trying to use in my project.
syms S AR PHI
%locations of observation points
x1 = -9.72; y1 = -5.62; %OBS4
x2 = -4.95; y2 = -5.60; %OBS5
x3 = 6.63; y3 = -3.76; %OBS6
%values for known variables
Sa1 = 1.0752e-05;
Sa2 = 1.0753e-05;
Sa3 = 1.0894e-05;
%interim variables
W1 = ((-x1*sind(PHI) + y1*cosd(PHI)) / (y1*sind(PHI) + x1*cosd(PHI)));
W2 = ((-x2*sind(PHI) + y2*cosd(PHI)) / (y2*sind(PHI) + x2*cosd(PHI)));
W3 = ((-x3*sind(PHI) + y3*cosd(PHI)) / (y3*sind(PHI) + x3*cosd(PHI)));
%define system of equations and solve
EQN = [Sa1 == S*(sqrt(AR^-1)*(cosd(W1))^2+sqrt(AR)*(sind(W1))^2), …
Sa2 == S*(sqrt(AR^-1)*(cosd(W2))^2+sqrt(AR)*(sind(W2))^2), …
Sa3 == S*(sqrt(AR^-1)*(cosd(W3))^2+sqrt(AR)*(sind(W3))^2)];
[S,AR,PHI] = vpasolve(EQN)
The above code returns nonsense. Why?I’m trying to use vpasolve to solve a system of trigonomic equations. Known variables are Sa1, Sa2, and Sa3. Unknown variables are S, AR, PHI. The code hasn’t been giving me the correct results, but I can’t figure out where the error is.
Can someone with sharper eyes spot the problem?
I assigned fake values for the unknown variables, so I could calculate known variable values to test.
%locations of observation points
x1 = -9.72; y1 = -5.62; %OBS4
x2 = -4.95; y2 = -5.60; %OBS5
x3 = 6.63; y3 = -3.76; %OBS6
%assign fake values to unknown variables
S = 3.4e-5; AR = 10; PHI = 36;
%interim variables
W1 = ((-x1*sind(PHI) + y1*cosd(PHI)) / (y1*sind(PHI) + x1*cosd(PHI)));
W2 = ((-x2*sind(PHI) + y2*cosd(PHI)) / (y2*sind(PHI) + x2*cosd(PHI)));
W3 = ((-x3*sind(PHI) + y3*cosd(PHI)) / (y3*sind(PHI) + x3*cosd(PHI)));
%calculate known variable values to test
Sa1 = S*(sqrt(AR^-1)*(cosd(W1))^2+sqrt(AR)*(sind(W1))^2)
Sa2 = S*(sqrt(AR^-1)*(cosd(W2))^2+sqrt(AR)*(sind(W2))^2)
Sa3 = S*(sqrt(AR^-1)*(cosd(W3))^2+sqrt(AR)*(sind(W3))^2)
The above returns Sa1 = 1.0752e-05, Sa2 = 1.0753e-05, and Sa3 = 1.0894e-05.
Having created known variable values with my fake unknown variable values, I’m not able to return the numbers I assigned. The code below is what I’m trying to use in my project.
syms S AR PHI
%locations of observation points
x1 = -9.72; y1 = -5.62; %OBS4
x2 = -4.95; y2 = -5.60; %OBS5
x3 = 6.63; y3 = -3.76; %OBS6
%values for known variables
Sa1 = 1.0752e-05;
Sa2 = 1.0753e-05;
Sa3 = 1.0894e-05;
%interim variables
W1 = ((-x1*sind(PHI) + y1*cosd(PHI)) / (y1*sind(PHI) + x1*cosd(PHI)));
W2 = ((-x2*sind(PHI) + y2*cosd(PHI)) / (y2*sind(PHI) + x2*cosd(PHI)));
W3 = ((-x3*sind(PHI) + y3*cosd(PHI)) / (y3*sind(PHI) + x3*cosd(PHI)));
%define system of equations and solve
EQN = [Sa1 == S*(sqrt(AR^-1)*(cosd(W1))^2+sqrt(AR)*(sind(W1))^2), …
Sa2 == S*(sqrt(AR^-1)*(cosd(W2))^2+sqrt(AR)*(sind(W2))^2), …
Sa3 == S*(sqrt(AR^-1)*(cosd(W3))^2+sqrt(AR)*(sind(W3))^2)];
[S,AR,PHI] = vpasolve(EQN)
The above code returns nonsense. Why? I’m trying to use vpasolve to solve a system of trigonomic equations. Known variables are Sa1, Sa2, and Sa3. Unknown variables are S, AR, PHI. The code hasn’t been giving me the correct results, but I can’t figure out where the error is.
Can someone with sharper eyes spot the problem?
I assigned fake values for the unknown variables, so I could calculate known variable values to test.
%locations of observation points
x1 = -9.72; y1 = -5.62; %OBS4
x2 = -4.95; y2 = -5.60; %OBS5
x3 = 6.63; y3 = -3.76; %OBS6
%assign fake values to unknown variables
S = 3.4e-5; AR = 10; PHI = 36;
%interim variables
W1 = ((-x1*sind(PHI) + y1*cosd(PHI)) / (y1*sind(PHI) + x1*cosd(PHI)));
W2 = ((-x2*sind(PHI) + y2*cosd(PHI)) / (y2*sind(PHI) + x2*cosd(PHI)));
W3 = ((-x3*sind(PHI) + y3*cosd(PHI)) / (y3*sind(PHI) + x3*cosd(PHI)));
%calculate known variable values to test
Sa1 = S*(sqrt(AR^-1)*(cosd(W1))^2+sqrt(AR)*(sind(W1))^2)
Sa2 = S*(sqrt(AR^-1)*(cosd(W2))^2+sqrt(AR)*(sind(W2))^2)
Sa3 = S*(sqrt(AR^-1)*(cosd(W3))^2+sqrt(AR)*(sind(W3))^2)
The above returns Sa1 = 1.0752e-05, Sa2 = 1.0753e-05, and Sa3 = 1.0894e-05.
Having created known variable values with my fake unknown variable values, I’m not able to return the numbers I assigned. The code below is what I’m trying to use in my project.
syms S AR PHI
%locations of observation points
x1 = -9.72; y1 = -5.62; %OBS4
x2 = -4.95; y2 = -5.60; %OBS5
x3 = 6.63; y3 = -3.76; %OBS6
%values for known variables
Sa1 = 1.0752e-05;
Sa2 = 1.0753e-05;
Sa3 = 1.0894e-05;
%interim variables
W1 = ((-x1*sind(PHI) + y1*cosd(PHI)) / (y1*sind(PHI) + x1*cosd(PHI)));
W2 = ((-x2*sind(PHI) + y2*cosd(PHI)) / (y2*sind(PHI) + x2*cosd(PHI)));
W3 = ((-x3*sind(PHI) + y3*cosd(PHI)) / (y3*sind(PHI) + x3*cosd(PHI)));
%define system of equations and solve
EQN = [Sa1 == S*(sqrt(AR^-1)*(cosd(W1))^2+sqrt(AR)*(sind(W1))^2), …
Sa2 == S*(sqrt(AR^-1)*(cosd(W2))^2+sqrt(AR)*(sind(W2))^2), …
Sa3 == S*(sqrt(AR^-1)*(cosd(W3))^2+sqrt(AR)*(sind(W3))^2)];
[S,AR,PHI] = vpasolve(EQN)
The above code returns nonsense. Why? vpasolv, symbolic MATLAB Answers — New Questions
Gtk-Message: 10:32:31.466: Failed to load module “canberra-gtk-module”
I installed matlab 2019a with update3 on ubuntu 16.04 64bit. When I run matlab, I got output: Gtk-Message: 10:32:31.466: Failed to load module "canberra-gtk-module".
How to sort this problem.
Thanks in advance.I installed matlab 2019a with update3 on ubuntu 16.04 64bit. When I run matlab, I got output: Gtk-Message: 10:32:31.466: Failed to load module "canberra-gtk-module".
How to sort this problem.
Thanks in advance. I installed matlab 2019a with update3 on ubuntu 16.04 64bit. When I run matlab, I got output: Gtk-Message: 10:32:31.466: Failed to load module "canberra-gtk-module".
How to sort this problem.
Thanks in advance. start up MATLAB Answers — New Questions
Compiled version fails when highpass is called “Error using toolboxdir. Could not locate the base directory for dsp/filterdesign’.
I have created an App in App Designer which works fine until I compile. Everything still works as expected, except the functionality that uses the ‘highpass’ function from the Signal Processing toolbox. The log file states:
"Error using toolboxdir (line 54)
Could not locate the base directory for dsp/filterdesign.
I have checked that the toolbox is installed (I even reinstalled it again) and checked the path to the toolbox exists using toolboxdir(‘signal’).
I created a small test app that recreates the problem.The test app simply creates 100 random numbers, plots them and then applies the highpass filter on the click of a button. Again, the application fails once it is compiled.
I read that the Matlab compiler should detect and automatically include any toolbox requirements. I even tried forcing this detection by adding some non-consequential calls to highpass.m . The code for the test application is below.
Can anybody suggest what I am doing wrong?
classdef testHighPass < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
FilterButton matlab.ui.control.Button
GenerateDataButton matlab.ui.control.Button
plotAxes matlab.ui.control.UIAxes
end
properties (Access = private)
data % Description
x
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: GenerateDataButton
function GenerateDataButtonPushed(app, event)
app.data = rand(1, 100);
app.x = 1:100;
hold(app.plotAxes, ‘off’);
plot(app.plotAxes, app.x, app.data);
hold(app.plotAxes,’on’)
end
% Button pushed function: FilterButton
function FilterButtonPushed(app, event)
filt_data = highpass(app.data, 0.8);
plot(app.plotAxes, app.x, filt_data, ‘r’);
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure(‘Visible’, ‘off’);
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = ‘MATLAB App’;
% Create plotAxes
app.plotAxes = uiaxes(app.UIFigure);
title(app.plotAxes, ‘Data’)
xlabel(app.plotAxes, ‘X’)
ylabel(app.plotAxes, ‘Y’)
zlabel(app.plotAxes, ‘Z’)
app.plotAxes.Position = [101 161 446 280];
% Create GenerateDataButton
app.GenerateDataButton = uibutton(app.UIFigure, ‘push’);
app.GenerateDataButton.ButtonPushedFcn = createCallbackFcn(app, @GenerateDataButtonPushed, true);
app.GenerateDataButton.Position = [74 95 122 37];
app.GenerateDataButton.Text = ‘Generate Data’;
% Create FilterButton
app.FilterButton = uibutton(app.UIFigure, ‘push’);
app.FilterButton.ButtonPushedFcn = createCallbackFcn(app, @FilterButtonPushed, true);
app.FilterButton.Position = [399 96 130 35];
app.FilterButton.Text = ‘Filter’;
% Show the figure after all components are created
app.UIFigure.Visible = ‘on’;
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = testHighPass
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
endI have created an App in App Designer which works fine until I compile. Everything still works as expected, except the functionality that uses the ‘highpass’ function from the Signal Processing toolbox. The log file states:
"Error using toolboxdir (line 54)
Could not locate the base directory for dsp/filterdesign.
I have checked that the toolbox is installed (I even reinstalled it again) and checked the path to the toolbox exists using toolboxdir(‘signal’).
I created a small test app that recreates the problem.The test app simply creates 100 random numbers, plots them and then applies the highpass filter on the click of a button. Again, the application fails once it is compiled.
I read that the Matlab compiler should detect and automatically include any toolbox requirements. I even tried forcing this detection by adding some non-consequential calls to highpass.m . The code for the test application is below.
Can anybody suggest what I am doing wrong?
classdef testHighPass < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
FilterButton matlab.ui.control.Button
GenerateDataButton matlab.ui.control.Button
plotAxes matlab.ui.control.UIAxes
end
properties (Access = private)
data % Description
x
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: GenerateDataButton
function GenerateDataButtonPushed(app, event)
app.data = rand(1, 100);
app.x = 1:100;
hold(app.plotAxes, ‘off’);
plot(app.plotAxes, app.x, app.data);
hold(app.plotAxes,’on’)
end
% Button pushed function: FilterButton
function FilterButtonPushed(app, event)
filt_data = highpass(app.data, 0.8);
plot(app.plotAxes, app.x, filt_data, ‘r’);
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure(‘Visible’, ‘off’);
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = ‘MATLAB App’;
% Create plotAxes
app.plotAxes = uiaxes(app.UIFigure);
title(app.plotAxes, ‘Data’)
xlabel(app.plotAxes, ‘X’)
ylabel(app.plotAxes, ‘Y’)
zlabel(app.plotAxes, ‘Z’)
app.plotAxes.Position = [101 161 446 280];
% Create GenerateDataButton
app.GenerateDataButton = uibutton(app.UIFigure, ‘push’);
app.GenerateDataButton.ButtonPushedFcn = createCallbackFcn(app, @GenerateDataButtonPushed, true);
app.GenerateDataButton.Position = [74 95 122 37];
app.GenerateDataButton.Text = ‘Generate Data’;
% Create FilterButton
app.FilterButton = uibutton(app.UIFigure, ‘push’);
app.FilterButton.ButtonPushedFcn = createCallbackFcn(app, @FilterButtonPushed, true);
app.FilterButton.Position = [399 96 130 35];
app.FilterButton.Text = ‘Filter’;
% Show the figure after all components are created
app.UIFigure.Visible = ‘on’;
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = testHighPass
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end I have created an App in App Designer which works fine until I compile. Everything still works as expected, except the functionality that uses the ‘highpass’ function from the Signal Processing toolbox. The log file states:
"Error using toolboxdir (line 54)
Could not locate the base directory for dsp/filterdesign.
I have checked that the toolbox is installed (I even reinstalled it again) and checked the path to the toolbox exists using toolboxdir(‘signal’).
I created a small test app that recreates the problem.The test app simply creates 100 random numbers, plots them and then applies the highpass filter on the click of a button. Again, the application fails once it is compiled.
I read that the Matlab compiler should detect and automatically include any toolbox requirements. I even tried forcing this detection by adding some non-consequential calls to highpass.m . The code for the test application is below.
Can anybody suggest what I am doing wrong?
classdef testHighPass < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
FilterButton matlab.ui.control.Button
GenerateDataButton matlab.ui.control.Button
plotAxes matlab.ui.control.UIAxes
end
properties (Access = private)
data % Description
x
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: GenerateDataButton
function GenerateDataButtonPushed(app, event)
app.data = rand(1, 100);
app.x = 1:100;
hold(app.plotAxes, ‘off’);
plot(app.plotAxes, app.x, app.data);
hold(app.plotAxes,’on’)
end
% Button pushed function: FilterButton
function FilterButtonPushed(app, event)
filt_data = highpass(app.data, 0.8);
plot(app.plotAxes, app.x, filt_data, ‘r’);
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure(‘Visible’, ‘off’);
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = ‘MATLAB App’;
% Create plotAxes
app.plotAxes = uiaxes(app.UIFigure);
title(app.plotAxes, ‘Data’)
xlabel(app.plotAxes, ‘X’)
ylabel(app.plotAxes, ‘Y’)
zlabel(app.plotAxes, ‘Z’)
app.plotAxes.Position = [101 161 446 280];
% Create GenerateDataButton
app.GenerateDataButton = uibutton(app.UIFigure, ‘push’);
app.GenerateDataButton.ButtonPushedFcn = createCallbackFcn(app, @GenerateDataButtonPushed, true);
app.GenerateDataButton.Position = [74 95 122 37];
app.GenerateDataButton.Text = ‘Generate Data’;
% Create FilterButton
app.FilterButton = uibutton(app.UIFigure, ‘push’);
app.FilterButton.ButtonPushedFcn = createCallbackFcn(app, @FilterButtonPushed, true);
app.FilterButton.Position = [399 96 130 35];
app.FilterButton.Text = ‘Filter’;
% Show the figure after all components are created
app.UIFigure.Visible = ‘on’;
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = testHighPass
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end runtime error, toolboxdir, base directory MATLAB Answers — New Questions
SNR comparison real/complex signal
Hello,
I have a problem which should be simple but I can’t figure out the best solution.
I have a real signal, cos of frequency f + noise of N points :
signal = sqrt(2 * Ps) * cos(2 * pi * f *t);
noise = sqrt(Pn) * randn(1, N);
total = signal + noise;
I consider the SNR on the whole signal Ps/Pn that I also check using
(mean(abs(signal.^2)) – mean(abs(noise.^2))) / mean(abs(noise.^2))
I filter this signal using a simple FFT of nFFT points and consider an extraction in the signal canal. For instance, with f / fs = 1/4, I consider the nFFT / 4 + 1 canal. Plotting the signal spectrum, I ensure the signal is centered in the FFT canal. Then I compute :
The power in the canal : PsCanal = mean(abs(samplesCanalWithSignal.^2)).
The noise level in a random other canal : PnCanal = mean(abs(samplesCanalWithoutSignal.^2))
And compute SNR in the canal : SNRCanal = (PsCanal – PnCanal) / PnCanal.
Now I consider a complex signal. Same time, fe, etc… I only change signal and noise definition in order to have same global powers :
signal = sqrt(Ps) * exp(2i * pi * f *t)
noise = sqrt(Pn / 2) *(randn(1, N) + 1i * randn(1, N))
total = signal + noise
When I compute the global RSB, I have the exact same RSB than with real signal.
Then I compute the FFT (same nFFT points) and compute SNRCanal = (PsCanal – PnCanal) / PnCanal
Result is the following (compared to real signal test) :
Same PnCanal
PsCanal multiplied by 2
RSBCanal multiplied by 2
Where am I wrong ? I would like to be able to estimate the correct SNR in the FFT canal for real signals… I understand the PSD of the cos is half the one of exp due to positive and negative frequencies, but don’t understand why it is not the case for the noise PSD. Do I have to transform something ?
Thank youHello,
I have a problem which should be simple but I can’t figure out the best solution.
I have a real signal, cos of frequency f + noise of N points :
signal = sqrt(2 * Ps) * cos(2 * pi * f *t);
noise = sqrt(Pn) * randn(1, N);
total = signal + noise;
I consider the SNR on the whole signal Ps/Pn that I also check using
(mean(abs(signal.^2)) – mean(abs(noise.^2))) / mean(abs(noise.^2))
I filter this signal using a simple FFT of nFFT points and consider an extraction in the signal canal. For instance, with f / fs = 1/4, I consider the nFFT / 4 + 1 canal. Plotting the signal spectrum, I ensure the signal is centered in the FFT canal. Then I compute :
The power in the canal : PsCanal = mean(abs(samplesCanalWithSignal.^2)).
The noise level in a random other canal : PnCanal = mean(abs(samplesCanalWithoutSignal.^2))
And compute SNR in the canal : SNRCanal = (PsCanal – PnCanal) / PnCanal.
Now I consider a complex signal. Same time, fe, etc… I only change signal and noise definition in order to have same global powers :
signal = sqrt(Ps) * exp(2i * pi * f *t)
noise = sqrt(Pn / 2) *(randn(1, N) + 1i * randn(1, N))
total = signal + noise
When I compute the global RSB, I have the exact same RSB than with real signal.
Then I compute the FFT (same nFFT points) and compute SNRCanal = (PsCanal – PnCanal) / PnCanal
Result is the following (compared to real signal test) :
Same PnCanal
PsCanal multiplied by 2
RSBCanal multiplied by 2
Where am I wrong ? I would like to be able to estimate the correct SNR in the FFT canal for real signals… I understand the PSD of the cos is half the one of exp due to positive and negative frequencies, but don’t understand why it is not the case for the noise PSD. Do I have to transform something ?
Thank you Hello,
I have a problem which should be simple but I can’t figure out the best solution.
I have a real signal, cos of frequency f + noise of N points :
signal = sqrt(2 * Ps) * cos(2 * pi * f *t);
noise = sqrt(Pn) * randn(1, N);
total = signal + noise;
I consider the SNR on the whole signal Ps/Pn that I also check using
(mean(abs(signal.^2)) – mean(abs(noise.^2))) / mean(abs(noise.^2))
I filter this signal using a simple FFT of nFFT points and consider an extraction in the signal canal. For instance, with f / fs = 1/4, I consider the nFFT / 4 + 1 canal. Plotting the signal spectrum, I ensure the signal is centered in the FFT canal. Then I compute :
The power in the canal : PsCanal = mean(abs(samplesCanalWithSignal.^2)).
The noise level in a random other canal : PnCanal = mean(abs(samplesCanalWithoutSignal.^2))
And compute SNR in the canal : SNRCanal = (PsCanal – PnCanal) / PnCanal.
Now I consider a complex signal. Same time, fe, etc… I only change signal and noise definition in order to have same global powers :
signal = sqrt(Ps) * exp(2i * pi * f *t)
noise = sqrt(Pn / 2) *(randn(1, N) + 1i * randn(1, N))
total = signal + noise
When I compute the global RSB, I have the exact same RSB than with real signal.
Then I compute the FFT (same nFFT points) and compute SNRCanal = (PsCanal – PnCanal) / PnCanal
Result is the following (compared to real signal test) :
Same PnCanal
PsCanal multiplied by 2
RSBCanal multiplied by 2
Where am I wrong ? I would like to be able to estimate the correct SNR in the FFT canal for real signals… I understand the PSD of the cos is half the one of exp due to positive and negative frequencies, but don’t understand why it is not the case for the noise PSD. Do I have to transform something ?
Thank you snr MATLAB Answers — New Questions
How to get holidays and business days from non-US countries in Financial Toolbox?
How do I get holidays and business days from countries other than the United States in Financial Toolbox?
The ‘holidays’ function only returns US holidays.How do I get holidays and business days from countries other than the United States in Financial Toolbox?
The ‘holidays’ function only returns US holidays. How do I get holidays and business days from countries other than the United States in Financial Toolbox?
The ‘holidays’ function only returns US holidays. holiday, businessday, isbusday, business MATLAB Answers — New Questions
How to initialize the Hammerstein model linear block and avoiding that the nlhw function transform the linear block to polynomial form ?
Hi.
I am trying to estiamte a Hammerstein Model. I have a state representation of the linear block to generate the Hammerstein model, however for some reason the idnlhw function convert the state representation that I have to polynomial form. The above should not be a problem, but the poles of linear block are close together due to the slow dynamcis of my system. From what i read in this post https://la.mathworks.com/help/control/ug/sensitivity-of-multiple-roots.html closelied space poles are very sensitivy to model transformaiton from state space to polynomial represntation.
The above becomes problematic because I want to program this model in a 32-bit microncontroller but this pole sensitivy changes the value of my poles when I convert them to single precision.
How can I solve this issue.Hi.
I am trying to estiamte a Hammerstein Model. I have a state representation of the linear block to generate the Hammerstein model, however for some reason the idnlhw function convert the state representation that I have to polynomial form. The above should not be a problem, but the poles of linear block are close together due to the slow dynamcis of my system. From what i read in this post https://la.mathworks.com/help/control/ug/sensitivity-of-multiple-roots.html closelied space poles are very sensitivy to model transformaiton from state space to polynomial represntation.
The above becomes problematic because I want to program this model in a 32-bit microncontroller but this pole sensitivy changes the value of my poles when I convert them to single precision.
How can I solve this issue. Hi.
I am trying to estiamte a Hammerstein Model. I have a state representation of the linear block to generate the Hammerstein model, however for some reason the idnlhw function convert the state representation that I have to polynomial form. The above should not be a problem, but the poles of linear block are close together due to the slow dynamcis of my system. From what i read in this post https://la.mathworks.com/help/control/ug/sensitivity-of-multiple-roots.html closelied space poles are very sensitivy to model transformaiton from state space to polynomial represntation.
The above becomes problematic because I want to program this model in a 32-bit microncontroller but this pole sensitivy changes the value of my poles when I convert them to single precision.
How can I solve this issue. hammerstein model, system identification MATLAB Answers — New Questions
How can I live-stream and visualize signals from my Speedgoat target computer running a real-time application?
What are the different methods to live-stream and visualize signals from Speedgoat hardware running a real-time application, and how can each method be configured?What are the different methods to live-stream and visualize signals from Speedgoat hardware running a real-time application, and how can each method be configured? What are the different methods to live-stream and visualize signals from Speedgoat hardware running a real-time application, and how can each method be configured? real-time, signal, streaming, tracing MATLAB Answers — New Questions
What system of ODE’s does Simscape Electrical’s DC Motor Block use?
I’ve been having trouble getting the DC Motor block’s results for current and rotational velocity to match what I obtain when using coupled differential equations in an ODE45 script. The results are very far apart and I’m not sure what is causing this.
The systems of equations I’ve implemented in ODE45 is standard in the DC motor literature, and is as follows:
Where is the current (), is the armature inductance (), is the armature resistance (), is the motor electrical constant (), is the voltage of the constant voltage source (), is the armature’s mass moment of inertia (), is the motor’s torque constant (), and is the motor damping ().
However, I’ve noticed that in the DC Motor block documentation, the equation for torque across the motor is given as (where is the damping constant). When I add the first term into my differential equation model, the results of ODE45 and Simscape Electrical become very close. I assume that this is the set of equations that Simscape is using, but I don’t like to use equations without understanding them. Where does this added term come from? I don’t believe I’ve seen it in the literature.
I’ve attached plots showing current and rotational velocity of the motor for the three models, so that you can see the discrepancies. (Note that there is zero damping in any of the models, yet only the classical differential equation model shows a rising angular velocity — the other models eventually reach some steady-state non-zero angular velocity.)
Any insight into what is happening here would be appreciated.I’ve been having trouble getting the DC Motor block’s results for current and rotational velocity to match what I obtain when using coupled differential equations in an ODE45 script. The results are very far apart and I’m not sure what is causing this.
The systems of equations I’ve implemented in ODE45 is standard in the DC motor literature, and is as follows:
Where is the current (), is the armature inductance (), is the armature resistance (), is the motor electrical constant (), is the voltage of the constant voltage source (), is the armature’s mass moment of inertia (), is the motor’s torque constant (), and is the motor damping ().
However, I’ve noticed that in the DC Motor block documentation, the equation for torque across the motor is given as (where is the damping constant). When I add the first term into my differential equation model, the results of ODE45 and Simscape Electrical become very close. I assume that this is the set of equations that Simscape is using, but I don’t like to use equations without understanding them. Where does this added term come from? I don’t believe I’ve seen it in the literature.
I’ve attached plots showing current and rotational velocity of the motor for the three models, so that you can see the discrepancies. (Note that there is zero damping in any of the models, yet only the classical differential equation model shows a rising angular velocity — the other models eventually reach some steady-state non-zero angular velocity.)
Any insight into what is happening here would be appreciated. I’ve been having trouble getting the DC Motor block’s results for current and rotational velocity to match what I obtain when using coupled differential equations in an ODE45 script. The results are very far apart and I’m not sure what is causing this.
The systems of equations I’ve implemented in ODE45 is standard in the DC motor literature, and is as follows:
Where is the current (), is the armature inductance (), is the armature resistance (), is the motor electrical constant (), is the voltage of the constant voltage source (), is the armature’s mass moment of inertia (), is the motor’s torque constant (), and is the motor damping ().
However, I’ve noticed that in the DC Motor block documentation, the equation for torque across the motor is given as (where is the damping constant). When I add the first term into my differential equation model, the results of ODE45 and Simscape Electrical become very close. I assume that this is the set of equations that Simscape is using, but I don’t like to use equations without understanding them. Where does this added term come from? I don’t believe I’ve seen it in the literature.
I’ve attached plots showing current and rotational velocity of the motor for the three models, so that you can see the discrepancies. (Note that there is zero damping in any of the models, yet only the classical differential equation model shows a rising angular velocity — the other models eventually reach some steady-state non-zero angular velocity.)
Any insight into what is happening here would be appreciated. simscape, differential equations MATLAB Answers — New Questions
N-dimension curve fit how to
Can someone please walk me through how to do a polynomial curve fit to n-dimensional data? For example: I have a 3D matrix t = [i x j x k] of results for all combinations of 3 different variables x = [i x 1], y = [j x 1], and z = [k x 1], and we know it follows a polynomial fit (e.g. x = 4th order, y = 2nd order, and z = 2nd order). How do I set up the problem, define the fit equation, and find the fit parameters?Can someone please walk me through how to do a polynomial curve fit to n-dimensional data? For example: I have a 3D matrix t = [i x j x k] of results for all combinations of 3 different variables x = [i x 1], y = [j x 1], and z = [k x 1], and we know it follows a polynomial fit (e.g. x = 4th order, y = 2nd order, and z = 2nd order). How do I set up the problem, define the fit equation, and find the fit parameters? Can someone please walk me through how to do a polynomial curve fit to n-dimensional data? For example: I have a 3D matrix t = [i x j x k] of results for all combinations of 3 different variables x = [i x 1], y = [j x 1], and z = [k x 1], and we know it follows a polynomial fit (e.g. x = 4th order, y = 2nd order, and z = 2nd order). How do I set up the problem, define the fit equation, and find the fit parameters? regression, curve fitting, polyfit MATLAB Answers — New Questions
Error trying to link Matlab and Aspen Plus
I have error message while trying to link Matlab with my Aspen Plus simulation:
>> CHLC
Error using COM.Apwn_Document_37_0/invoke
Invoke Error, Dispatch Exception:
Source: Aspen Plus 37.0 OLE Services
Description: Unable to open file.
Error in CHLC (line 8)
Aspen.invoke(‘InitFromFile’,[mess.Name ” Simulation_Name ‘.apwz’]);
This is the code im using:
%% Linking
Aspen = actxserver(‘Apwn.Document.37.0’);
[stat,mess]=fileattrib; % get attributes of folder (Necessary to establish the location of the simulation)
Simulation_Name = ‘CL_SCO2’;% Aspeen Plus Simulation Name
Aspen.invoke(‘InitFromArchive2’,[mess.Name ” Simulation_Name ‘.bkp’]);
Aspen.Visible = 1; % 1 —> Aspen is Visible; 0 —> Aspen is open but not visible
Aspen.SuppressDialogs = 1; % Suppress windows dialogs.
Aspen.Engine.Run2(1); % Run the simulation
while Aspen.Engine.IsRunning == 1 % 1 –> If Aspen is running; 0 —> If Aspen stop.
pause(0.5);
end
Matlab version is R2022a (9.12.0.1884302) 64-bit and Aspen plus V11 (37.0.0395)
Already try saving Aspen simulation as .bkp and .apwz.
Yes, two files ( .m matlab code and .awpz / .bkp simulation) are in the same folder.I have error message while trying to link Matlab with my Aspen Plus simulation:
>> CHLC
Error using COM.Apwn_Document_37_0/invoke
Invoke Error, Dispatch Exception:
Source: Aspen Plus 37.0 OLE Services
Description: Unable to open file.
Error in CHLC (line 8)
Aspen.invoke(‘InitFromFile’,[mess.Name ” Simulation_Name ‘.apwz’]);
This is the code im using:
%% Linking
Aspen = actxserver(‘Apwn.Document.37.0’);
[stat,mess]=fileattrib; % get attributes of folder (Necessary to establish the location of the simulation)
Simulation_Name = ‘CL_SCO2’;% Aspeen Plus Simulation Name
Aspen.invoke(‘InitFromArchive2’,[mess.Name ” Simulation_Name ‘.bkp’]);
Aspen.Visible = 1; % 1 —> Aspen is Visible; 0 —> Aspen is open but not visible
Aspen.SuppressDialogs = 1; % Suppress windows dialogs.
Aspen.Engine.Run2(1); % Run the simulation
while Aspen.Engine.IsRunning == 1 % 1 –> If Aspen is running; 0 —> If Aspen stop.
pause(0.5);
end
Matlab version is R2022a (9.12.0.1884302) 64-bit and Aspen plus V11 (37.0.0395)
Already try saving Aspen simulation as .bkp and .apwz.
Yes, two files ( .m matlab code and .awpz / .bkp simulation) are in the same folder. I have error message while trying to link Matlab with my Aspen Plus simulation:
>> CHLC
Error using COM.Apwn_Document_37_0/invoke
Invoke Error, Dispatch Exception:
Source: Aspen Plus 37.0 OLE Services
Description: Unable to open file.
Error in CHLC (line 8)
Aspen.invoke(‘InitFromFile’,[mess.Name ” Simulation_Name ‘.apwz’]);
This is the code im using:
%% Linking
Aspen = actxserver(‘Apwn.Document.37.0’);
[stat,mess]=fileattrib; % get attributes of folder (Necessary to establish the location of the simulation)
Simulation_Name = ‘CL_SCO2’;% Aspeen Plus Simulation Name
Aspen.invoke(‘InitFromArchive2’,[mess.Name ” Simulation_Name ‘.bkp’]);
Aspen.Visible = 1; % 1 —> Aspen is Visible; 0 —> Aspen is open but not visible
Aspen.SuppressDialogs = 1; % Suppress windows dialogs.
Aspen.Engine.Run2(1); % Run the simulation
while Aspen.Engine.IsRunning == 1 % 1 –> If Aspen is running; 0 —> If Aspen stop.
pause(0.5);
end
Matlab version is R2022a (9.12.0.1884302) 64-bit and Aspen plus V11 (37.0.0395)
Already try saving Aspen simulation as .bkp and .apwz.
Yes, two files ( .m matlab code and .awpz / .bkp simulation) are in the same folder. aspen puls, matlab, link, error MATLAB Answers — New Questions
What is the best method to model or utilize the built-in model for a three-phase voltage regulator in MATLAB Simulink, specifically for the IEEE 34 distribution network?
What is the best method to model or use the built-in model for a three-phase voltage regulator in MATLAB Simulink, specifically for the IEEE 34 distribution network, in a way that works properly with load flow analysis from the Powergui?What is the best method to model or use the built-in model for a three-phase voltage regulator in MATLAB Simulink, specifically for the IEEE 34 distribution network, in a way that works properly with load flow analysis from the Powergui? What is the best method to model or use the built-in model for a three-phase voltage regulator in MATLAB Simulink, specifically for the IEEE 34 distribution network, in a way that works properly with load flow analysis from the Powergui? matlab, simulink, voltage regulator, ieee 34, load MATLAB Answers — New Questions
how can i draw contourf plot
I’m going to make a plot like this picture.
I interpolated the data using the interp1 function. However, contourf can only contain values of 2*2 or more, so the function cannot be executed. How do I solve this?I’m going to make a plot like this picture.
I interpolated the data using the interp1 function. However, contourf can only contain values of 2*2 or more, so the function cannot be executed. How do I solve this? I’m going to make a plot like this picture.
I interpolated the data using the interp1 function. However, contourf can only contain values of 2*2 or more, so the function cannot be executed. How do I solve this? #argo, #interp1, #ocean, #pressure, #temperature, #salinty, #contourf MATLAB Answers — New Questions
how do i model power increment (+udeg, -udeg) limits using matlab function?
how do i model power increment (+udeg, -udeg) limits using matlab function?(sign function)
i am working on power system having constraints.
Thanks in advancehow do i model power increment (+udeg, -udeg) limits using matlab function?(sign function)
i am working on power system having constraints.
Thanks in advance how do i model power increment (+udeg, -udeg) limits using matlab function?(sign function)
i am working on power system having constraints.
Thanks in advance sign function MATLAB Answers — New Questions
Assistance with Load Flow Analysis in IEEE 34 Distribution Network on MATLAB-Simulink
Hello,
I am working with the IEEE 34-bus distribution network in MATLAB-Simulink. When running the load flow analysis after setting up the buses, I encountered the following error message:
"Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.218374e-17."
Given that this is an unbalanced system, could you please advise on the potential causes of this issue?How to solve it? Additionally, are there alternative methods or tools within MATLAB-Simulink to handle load flow analysis for such systems?
Thank you for your assistance.
Best regards,Hello,
I am working with the IEEE 34-bus distribution network in MATLAB-Simulink. When running the load flow analysis after setting up the buses, I encountered the following error message:
"Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.218374e-17."
Given that this is an unbalanced system, could you please advise on the potential causes of this issue?How to solve it? Additionally, are there alternative methods or tools within MATLAB-Simulink to handle load flow analysis for such systems?
Thank you for your assistance.
Best regards, Hello,
I am working with the IEEE 34-bus distribution network in MATLAB-Simulink. When running the load flow analysis after setting up the buses, I encountered the following error message:
"Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.218374e-17."
Given that this is an unbalanced system, could you please advise on the potential causes of this issue?How to solve it? Additionally, are there alternative methods or tools within MATLAB-Simulink to handle load flow analysis for such systems?
Thank you for your assistance.
Best regards, ieee 34, load flow, matlab, simulink, unbalanced s MATLAB Answers — New Questions