How to Plot scatterplot in Single loop in App designer

Hello Everyone, I have 8 scatter plot, currently i am ploting it manually in app designer, i want to plot it in loop , the loop value start from 1:8
I have the following code.How can i modified it as for loop.
when we make for loop clusters{1} become clusters{i},
but main error in app.UIAxes_10
scatter(app.UIAxes_10,clusters{1}(:,1),clusters{1}(:,2))
scatter(app.UIAxes_11,clusters{2}(:,1),clusters{2}(:,2))
scatter(app.UIAxes_12,clusters{3}(:,1),clusters{3}(:,2))
scatter(app.UIAxes_13,clusters{4}(:,1),clusters{4}(:,2))
scatter(app.UIAxes_14,clusters{5}(:,1),clusters{5}(:,2))
scatter(app.UIAxes_15,clusters{6}(:,1),clusters{6}(:,2))
scatter(app.UIAxes_16,clusters{7}(:,1),clusters{7}(:,2))
scatter(app.UIAxes_17,clusters{8}(:,1),clusters{8}(:,2))
Loop code i tried
for i = 1:8
scatter(app.UIAxes_(i),clusters{i}(:,1),clusters{i}(:,2))
end

Answers (1)

@Med Future - if you create an array of your axes, then you will be able to loop over it. Something like the following might work
axesArray = {app.UIAxes_10, app.UIAxes_11, app.UIAxes_12, app.UIAxes_13, app.UIAxes_14, app.UIAxes_15, app.UIAxes_16, app.UIAxes_17};
for i = 1:8
scatter(axesArray{i},clusters{i}(:,1),clusters{i}(:,2))
end

6 Comments

How can i make this in loop?
app.NoClusterLabel.Text=CombineOutput(1).Prediction
app.NoClusterLabel_2.Text=CombineOutput(2).Prediction
app.NoClusterLabel_3.Text=CombineOutput(3).Prediction
app.NoClusterLabel_4.Text=CombineOutput(4).Prediction
app.NoClusterLabel_5.Text=CombineOutput(5).Prediction
app.NoClusterLabel_6.Text=CombineOutput(6).Prediction
app.NoClusterLabel_7.Text=CombineOutput(7).Prediction
app.NoClusterLabel_8.Text=CombineOutput(8).Prediction
@Stephen john - you could do something similar and put the text objects in an array.
@Stephen john - please show your code and the error message.
@Geoff Hayes Its no working. beacuse it does not plot app.NoClusterLabel_2 this one does not go to the loop
@Stephen john - please show your code and describe what is going wrong.

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Release

R2022a

Asked:

on 16 Jun 2022

Commented:

on 1 Jul 2022

Community Treasure Hunt

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

Start Hunting!