How to normalize rows using retmap.
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have a matrix A, where I would like to normalize all of the rows such that the sum of each individual row is 1 using retmap. If we have [1,2,3] --> [1/6, 2/6, 3/6]
My current approach is to loop through the matrix A, and grab the size of each row. For example.
[c d] = size(A)
for i=1:c
s = sum(A(i,;))
end
How would I utilize the retmap function such that we complete this function
0 Commenti
Risposte (1)
Adam Danz
il 16 Set 2021
Modificato: Adam Danz
il 17 Set 2021
I don't know what retmap is (did you mean repmat?)
Anyway, this normalizes the matrix by rows as you described,
% sample data
data = rand(20) .* randi(100,20,1)
% Normalize rows of 'data' so each row sums to 1
dataNorm = data./sum(data,2)
% confirm by adding values in each row
% The asser() will throw an error if any row does
% sum to 1, leaving room for precision error.
addedRows = sum(dataNorm,2);
assert(all(abs(addedRows-1)<1E10), 'Santify check failed: normalization is incorrect.')
0 Commenti
Vedere anche
Categorie
Scopri di più su Data Distribution Plots 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!