Clear Filters
Clear Filters

not able to calculate mean within the selected range

1 view (last 30 days)
Hi i have to calculate min,max and mean of y-axis within a range selected in x-axis.for range min and range max i have created 2 editboxes using guide .and am using one push button,when i push the button it should calculate min,max and mean of selected range and display in other 3 editboxes created for display.here is my code.please help
x=0:1:200;
data=get(handles.uitable1,'data');200*4 matrix
one=data(:,2);
x1= get(handles.min,'string') %value entered in editbox of tag min
x2= get(handles.max,'string') %value entered in editbox of tag max
range =[x1 x2]
start_pt = min( find( x >= range(1) ) )
end_pt = max( find( x <= range(2) ) )
y_in_range = one(start_pt:end_pt);
%min,max,mean
max_one = max(y_in_range)
min_one = min(y_in_range)
mean_one=mean(y_in_range)
set(handles.minimum, 'String',min_one)
set(handles.maximum, 'String',max_one)
set(handles.mean, 'String',mean_one)

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 11 Feb 2013
Edited: Azzi Abdelmalek on 11 Feb 2013
x1= get(handles.min,'string')
% is a string variable. Use instead
x1= str2double(get(handles.min,'string'))
%the same thing to store your data in a string property
set(handles.minimum, 'String',num2str(min_one))

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!