Error: Array indices must be positive integers or logical values
이전 댓글 표시
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
Walter Roberson
2021년 12월 5일
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
2021년 12월 5일
Walter Roberson
2021년 12월 5일
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)
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!