How do you graph Data filtered through a loop? This is for an app, I have a large table and a graph, but I also need to graph my filtered data.

1 回表示 (過去 30 日間)
% Code that executes after component creation
function startupFcn(app)
t = readtable('Corona 2.xlsx');
app.UITable.Data = t;
t = readtable('Corona 2.xlsx');
app.UITable.Data = t;
Day = table2array(t(:,"Day"));
Deaths = table2array(t(:,"Deaths"));
plot(app.UIAxes,Day,Deaths);
end
% Button pushed function: FilterStateButton
function FilterStateButtonPushed(app, event)
t = readtable('Corona 2.xlsx');
app.UITable.Data = t;
FilterState = app.StateFlipEditField.Value;
numRows = size(t,1);
k = 1;
for i = 1:numRows
if app.UITable.Data{i,4} ~= FilterState
RowstoDel(1,k) = i;
k = k + 1;
end
end
app.UITable.Data(RowstoDel,:) = [];
end
  2 件のコメント
darova
darova 2020 年 4 月 25 日
You are already plotting something. Isn't good?
Ashlan O'Brien
Ashlan O'Brien 2020 年 4 月 25 日
But I would like the plot to show UIAxes 2 as just the filtered state from the loop I created.

サインインしてコメントする。

回答 (1 件)

Ganesh Regoti
Ganesh Regoti 2020 年 4 月 29 日
Hi,
I assume that you want to plot the filtered data on another axis after the button is clicked. For this, either you could use another axes on the figure or you could use sub-plot.
function FilterStateButtonPushed(app, event)
t = readtable('Corona 2.xlsx');
app.UITable.Data = t;
FilterState = app.StateFlipEditField.Value;
numRows = size(t,1);
k = 1;
for i = 1:numRows
if app.UITable.Data{i,4} ~= FilterState
RowstoDel(1,k) = i;
k = k + 1;
end
end
app.UITable.Data(RowstoDel,:) = [];
plot(app.UIAxes2,Day,Deaths); % You could add something like this
% at the end of call back to plot the filtered data
end
You can also set visibility of an axes accordingly which is an in-build attribute for UIaxes.
Hope this helps!

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by