Error: Array indices must be positive integers or logical values
Mostrar comentarios más antiguos
I am trying to make a GUI that allows me to make a grid with the dimensions of the grid as inputs. My for loop works outisde of the 'guide' editor to do this, but when I copy and paste it into the GUI code with the proper callbacks, I get an "array indices must be positive integers or logical values" error. Some of my values are not integers and must stay that way. Please let me know what I can do to fix this.
here is the GUI code for just the pushbutton to run the function
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clc
s=str2double(get(handles.initial_x,'string'));
lowerbound=str2double(get(handles.initial_y,'string'));
f=str2double(get(handles.end_x,'string'));
upperbound=str2double(get(handles.end_y,'string'));
n=str2double(get(handles.slider1,'Value'));
x=linspace(s,f,n);
y=linspace(lowerbound,upperbound,n);
for i=1:n
xi=x;
yi=y(i)*ones(size(xi));
plot(xi,yi,'b')
hold on
end
for i=1:n
yi=y;
xi=x(i)*ones(size(yi));
plot(xi,yi,'b')
hold on
end
xl=s-20;
xu=f+20;
xlim([xl xu]);
3 comentarios
Walter Roberson
el 5 de Dic. de 2021
Which line is the error being reported for?
If you use the debugger and you dbstop if error then on the line that has the error, what shows up if you give the command
whos
Jack McNulty
el 5 de Dic. de 2021
Walter Roberson
el 5 de Dic. de 2021
As a debugging step, to track down the problem, at the command line give the command
dbstop if error
Then run your code. When the code stops due to the error, at the command line show us a complete copy of the error message, and show us the output of
whos
which ones
which size
disp(i)
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!