hi i have matrix of 90 columns and 1000 rows. i want if the sum of first row is greater than 9.29, then my code should search for minimum value and make it zero, but for some resons, my code not working for i=2. someone please help me fix it?
Show older comments
B=xlsread('userframe94.xlsx');
maxf=max(B);
maxframe=sum(maxf); %total maximum required bandwidth
p=0.25*maxframe; %here p=9.29
frame90=xlsread('frame90.xlsx');
i=2
counter=0;
s_row=sum(frame90(i,:));
x1=30;
while(s_row>p)
for j=1:90
diff=s_row-p;
x=abs(frame90(i,j)-diff);
if x<x1
x1=x; %i placed this condition to store min difference and correspondingly find index but
index=j; %its giving me same index for some values. how to fix it. Please run the code and %you will understand
end
end
frame90(i,index)=0;
counter=counter+1;
s_row=sum(frame90(i,:));
end
5 Comments
khaaluna
on 14 May 2014
Edited: Walter Roberson
on 14 May 2014
khaaluna
on 14 May 2014
Walter Roberson
on 14 May 2014
Have you considered using the two-output version of min() ?
Walter Roberson
on 14 May 2014
Within your "for j" you have
diff=s_row-p;
and neither s_row nor p are changed inside the "for j" loop. Therefore "diff" will be the same for all "j" values. If that is what you want, then why not initialize "diff" before the loop?
Note: using a variable named "diff" is likely to lead to difficulties as diff() is the name of a very useful MATLAB function.
khaaluna
on 15 May 2014
Answers (1)
Image Analyst
on 15 May 2014
Get both the minimum value, and it's location with this:
[minValue, indexAtMinValue] = min(yourArray);
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!