MATLAB: Finding the min value in a vector(column) without the program taking in consideration the zero values?

min

Hi Guys,
I am fairly new to Matlab, and still learning the simple stuff. Here is my challenge:
Its fairly straight forward. I have a excel sheet with 17 columns. In the first part of the program (see below), I just define the new matrix "raw data" which is exactly the same as excel just without any string, leaving just the columns I need. I am trying to find the min value in column 6 ( [Min_heel loc]=min(raw_data(1:end,6)); ), but there is a bunch of zero values before and after the non-zero values that I dont want the program to look through, because it obviously always takes the zero as the min. I cant use the if function in a loop because then it shifts the data of column 6 (new matrix) which I cant do since the location of that min value in column is very important relative to the other columns
The program works perfectly fine, I only have this one problem.
Any suggestions how to solve it? I really tried to find answers online, but could not succeed yet.
clc
clear
staticdata=xlsread('Static.xlsx');
meanvalue=mean(staticdata(6:16,:));
baseline=[meanvalue(1,4)-meanvalue(1,7),meanvalue(1,5)-meanvalue(1,8)];
sad = transpose(dir('*.csv' ));
z=1;
for file = sad;
disp( file.name );
FileName = (file.name);
[raw_data] = csvread(FileName,6,2);
[Min_heel loc]=min(raw_data(1:end,6));
shoeline=[raw_data(loc,2)-raw_data(loc,5),raw_data(loc,3)-raw_data(loc,6)];
angle=AOIfunction2(baseline,shoeline);
result1=[angle];
result1=num2cell(result1);
result1=[file.name,result1];
results(z,1:2)=result1;
z=z+1;
end
ColHeader = {'filename','angle',};
FileName_ex=['Results_','.xls'];
xlswrite([FileName_ex],ColHeader);
xlswrite([FileName_ex],[results],'sheet1','A2')
xlswrite([FileName_ex],[results],'sheet1','G2')
Thanks allot for any help in advance!
Regards, Jaco

Best Answer

In place of
[Min_heel loc]=min(raw_data(1:end,6));
put this:
f = find(raw_data(1:end,6)~=0); % or >0 if you prefer
[Min_heel loc]=min(raw_data(f,6));
loc = f(loc); % We need to correct 'loc'
Related Question