Index exceeds the number of array elements (0) in MATLAB app designer

2 views (last 30 days)
hold on;
xxx = flag_array; % 1 x 60001 array
yyy = ACSurfacedeflection_class2_array; % 1 x 60001 array
h1 = area(app.UIAxes,xxx,yyy);
set(h1(1),'FaceColor','g');
idx = find((ACSurfacedeflection_class2_array>=(0.075)) & (ACSurfacedeflection_class2_array<(0.090)));
h1=area(app.UIAxes,xxx(idx),yyy(idx));
set(h1(1),'FaceColor','y');
idx = find(ACSurfacedeflection_class2_array>=(0.090));
h1=area(app.UIAxes,xxx(idx),yyy(idx));
set(h1(1),'FaceColor','r');
hold off;
title(app.UIAxes, 'Class 2 Deflection vs Time');
xlabel(app.UIAxes, 'Time (hour)');
ylabel(app.UIAxes, 'Surfacedeflection (mm)');
app.UIAxes.Visible = 'on';
I keep getting Index exceeds the number of array elements (0) error at the line "set(h1(1),'FaceColor','y');" . Does anyone know how to solve this? I wrote a seperate .m script and it works fine there. Is there a way i can check the variables directly in the MATLAB app designer as we can do while writing scripts or .m file?

Accepted Answer

Mario Malic
Mario Malic on 1 Nov 2020
Hello,
You can try first getting rid of the index of h, even though it should work without it.
area is the child of UIAxes, if you have only one area plot, you can use this
set(findall(0, 'type', 'area'), 'FaceColor','y'); % First argument will return the handle to area
Otherwise, you can try changing properties with dot notation.
Area_H = findall(0, 'type', 'area')
% Area_H = app.UIAxes.Children(1) %
Area_H.FaceColor = 'g';
You can check them if you run your app from command window, or if you use debugging (IIRC). You can access app properties
app = NameOfYourApp
app.UIAxes %example
  1 Comment
Vinayak Chaturvedi
Vinayak Chaturvedi on 1 Nov 2020
Instead of hold on;
I used hold(app.UIAxes);
this worked for me !
Also, @Mario - Getting rid of index worked for me too (although i experimented it before even you commented here). Sometimes trial and error helps. Thanks for your help!

Sign in to comment.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!