Index exceeds the number of array elements (0) in MATLAB app designer
2 views (last 30 days)
Show older comments
Vinayak Chaturvedi
on 1 Nov 2020
Commented: Vinayak Chaturvedi
on 1 Nov 2020
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?
0 Comments
Accepted Answer
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
More Answers (0)
See Also
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!