what wrong with the fallowing codes?
2 次查看(过去 30 天)
显示 更早的评论
i have a 20*120 matrix for each column in the matrix i need to find the maximum value between all the values , and then sum the remaining values ,then i need to divide the maximum value by the summation of the remaining values. i tried this codes but the results were not correct what is the problem?
s=1:z %z=120
for i=1:x %x=20
maximss=max(Pres_W); %maximum value
InterFss=(sum(Pres_W))-maximss; %remaining values
SIRk(:,s)=(maximss(:,s))./(InterFss(:,s));
end
end
0 个评论
采纳的回答
John D'Errico
2016-5-22
Seems pretty straightforward, assuming I interpret your question properly.
% some completely arbitrary matrix
A = rand(20,120);
% maximum value for each column
mval = max(A,[],1);
% sum the remaining values, i.e., not including the maximum
% just compute the overall sum for each column, then subtract the max.
remsum = sum(A,1) - mval;
% divide the max by the remaining sum
mvalscaled = mval./remsum;
0 个评论
更多回答(1 个)
Image Analyst
2016-5-22
Here's the first part:
rows = 4;
columns = 20;
Pres_W = rand(rows, columns) $ Sample data.
% Get max in each column
columnMaxima = max(Pres_W, [], 1)
% Make same size as original matrix
columnMaxima = repmat(columnMaxima, [rows, 1])
% "find the maximum value between all the values"
differences = Pres_W - columnMaxima
maxDifference = max(differences(:))
But then I came to the instruction "sum the remaining values" and I had no idea what the remaining values were, and I couldn't see how your line of code gave the remaining values. Remaining after what???
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!