App Designer | Can't get back from 3D plot to 2D plot when changing list item

Hello,
Please assist me with my issue below. The code may seem lengthly but is simple.
I have an app where I change a list selection between 2D and 3D plots, however when changing back to 2D it shows my points on a 3D plot (please image attached).
Here's my plotting function:
function plotGraph(app, plotType, plotXt, plotYt, plotZt, plotTt, plotHt)
if nargin < 6
if nargin == 4
switch plotType
case 'Scatter'
scatter(app.UIAxes, plotXt, plotYt)
case 'Line'
plot(app.UIAxes, plotXt, plotYt)
case 'Histogram'
histogram(app.UIAxes, plotXt, plotYt)
end
else
switch plotType
case 'Scatter'
scatter3(app.UIAxes, plotXt, plotYt, plotZt)
case 'Line'
plot(app.UIAxes, plotXt, plotYt, plotZt)
case 'Histogram'
histogram(app.UIAxes, plotXt, plotYt, plotZt)
end
end
end
end
which I call via the listValueChanged function:
app.ListBoxPlotNames.ItemsData = 1:numel(app.ListBoxPlotNames.Items);
valueIndex = app.ListBoxPlotNames.ItemsData;
value = app.ListBoxPlotNames.Value
currentTable = initTable.data{value}
noColsDisp = width(currentTable)
plotX = table2array(currentTable(:,1))
plotY = table2array(currentTable(:,2))
switch noColsDisp
case 2
plotGraph(app, plotType, plotX, plotY);
case 3
%app.UITableImport.Data(:,3) = currentTable(:,3);
plotZ = table2array(currentTable(:,3))
plotGraph(app, plotType, plotX, plotY, plotZ);
end
When clicking on the ListBox function to go back to 2D I get this print out in command window:
currentTable =
10×2 table
Var1 Var2
______ ____
192.3 -9
192.31 -1
192.32 24
192.32 35
192.33 6
192.34 -4
192.34 6
192.35 20
192.36 4
192.37 6
% Note below noColsDisp = 2, therefore case 2 = plotGraph(app, plotType, plotX, plotY) should run (and to my knowledge does, but remains 3D?
noColsDisp =
2
plotX =
192.3024
192.3094
192.3164
192.3233
192.3303
192.3373
192.3442
192.3512
192.3582
192.3651
plotY =
-9
-1
24
35
6
-4
6
20
4
6
No plotZ is created?
Thank you for going through it and for your time.
Kind regards,
Connor

2 Comments

Shouldn't you be using plot3() and histogram2()?
Hi,
Can you try the following modified 'plotGraph' function & confirm if it works?
function plotGraph(app, plotType, plotXt, plotYt, plotZt, plotTt, plotHt)
app.UIAxes = [];
app.UIAxes = axes;
if nargin < 6
if nargin == 4
switch plotType
case 'Scatter'
scatter(app.UIAxes, plotXt, plotYt)
case 'Line'
plot(app.UIAxes, plotXt, plotYt)
case 'Histogram'
histogram(app.UIAxes, plotXt, plotYt)
end
else
switch plotType
case 'Scatter'
scatter3(app.UIAxes, plotXt, plotYt, plotZt)
case 'Line'
plot(app.UIAxes, plotXt, plotYt, plotZt)
case 'Histogram'
histogram(app.UIAxes, plotXt, plotYt, plotZt)
end
end
end
end

Sign in to comment.

Answers (0)

Asked:

on 17 Jan 2021

Commented:

on 24 Jan 2021

Community Treasure Hunt

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

Start Hunting!