Effacer les filtres
Effacer les filtres

what wrong with the fallowing codes?

1 vue (au cours des 30 derniers jours)
m. muner
m. muner le 22 Mai 2016
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

Réponse acceptée

John D'Errico
John D'Errico le 22 Mai 2016
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;

Plus de réponses (1)

Image Analyst
Image Analyst le 22 Mai 2016
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???

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by