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?

1 Ansicht (letzte 30 Tage)
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 Kommentare
Walter Roberson
Walter Roberson am 14 Mai 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
khaaluna am 15 Mai 2014
i dont understand what you mean by two output versions of min. s_row is sum of row and p is 9.29. i want to check the value in row which is nearer to diff=s_row-p. And make that value in zero on index found. if deleting one value doesn't solve problem then i want to search for another similar value to difference. That's why i used this method. As matlab dont have command for finding similar value. The problem here is that it goes right up-to some values but then it starts giving me same index so s_row wont decrease. I want to store different index every-time. Can you help?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 15 Mai 2014
Get both the minimum value, and it's location with this:
[minValue, indexAtMinValue] = min(yourArray);

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by