For a matrix with an unknown number of rows, how to find the number of rows n and transform it into n matrices.
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
8 commentaires
Réponse acceptée
Ameer Hamza
le 11 Déc 2020
Modifié(e) : Ameer Hamza
le 11 Déc 2020
You can find the number of rows in a matrix using size()
data1;
n = size(data,1)
or height() [only in R2020b and later]
data1;
n = height(data)
The second part of your question about transforming it into a matrix is not clear.
0 commentaires
Plus de réponses (1)
Ameer Hamza
le 11 Déc 2020
Modifié(e) : Ameer Hamza
le 11 Déc 2020
I guess you are trying to do something like this
rows = data1(:,2);
cols = data1(:,1);
M = zeros(max(rows), max(cols));
idx = sub2ind(size(M), rows, cols);
M(idx) = 1;
Result
>> imshow(M)
4 commentaires
Ameer Hamza
le 11 Déc 2020
You can use maxk() to get two largest values. For example
maxk(data1, 2)
gives 2 highest values in both columns.
Voir également
Catégories
En savoir plus sur NaNs 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!