In the below code, whenever a negative value is plugged into tmin, the function crashes. Please help.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuestas (1)
Debarati Banerjee
el 13 de Mayo de 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.
0 comentarios
Ver también
Categorías
Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!