Azzera filtri
Azzera filtri

what wrong with the fallowing codes?

1 visualizzazione (ultimi 30 giorni)
m. muner
m. muner il 22 Mag 2016
Risposto: John D'Errico il 22 Mag 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

Risposta accettata

John D'Errico
John D'Errico il 22 Mag 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;

Più risposte (1)

Image Analyst
Image Analyst il 22 Mag 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???

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by