In the below code, whenever a negative value is plugged into tmin, the function crashes. Please help.

1 view (last 30 days)
In the below code, the tmin value whenever made to reach a negative automatically gives this error:
'Subscript indices must either be real positive integers or logicals.'
tmin is a 17x1 matrix which has a few negative values. The full code is typed below. No other aspect of the code shows error.
% --- Executes on selection change in species.
function species_Callback(hObject, eventdata, handles)
% hObject handle to species (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns species contents as cell array
% contents{get(hObject,'Value')} returns selected item from species
load('data.mat')
i=get(hObject,'Value')
set(handles.edit_a,'String',A(i))
set(handles.edit_b,'String',B(i))
set(handles.edit_c,'String',C(i))
set(handles.edit_tmin,'String',tmin(i))
set(handles.edit_tmax,'String',tmax(i))
set(handles.edit_graphtitle,'String',Species(i))
T=((tmin(i)):(tmax(i)));
P(T)= (10^(((A(i)*(C(i)+T))-B(i))/(C(i)+T)));
plot(T,P(T))
xlabel(handles.axes_vp,'Temperature');
ylabel(handles.axes_vp,'Saturation Pressure')
Also, P only manages to sub in the first value of the range specified in T and not the rest, hence giving a flat line parallel to the x-axis rather than a curve. Note: All the above mentioned quantities are also 17x1 arrays such as A, B, C, tmin and tmax. The axes are working fine and change accordingly to the item selected in 'Species'(also a 17x1 array)
Any help would be appreciated.

Answers (1)

Debarati Banerjee
Debarati Banerjee on 13 May 2015
You get this type of error when you attempt to index into a matrix or vector using a set of indices that include a number that is not a positive integer or a logical value.
Looking at the code I think that the vector 'T' may be containing negative values which you are later on using as indices for array P. This is triggering the error most likely. Make sure that the vector T which you are using as indices for array P contains only positive integers.
To understand which line of the code is triggering the error, you may consider to Debug the code.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!