hwo can i solve matlab error in this code
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
sara alaraby
le 1 Fév 2019
Réponse apportée : Star Strider
le 1 Fév 2019
Dear;
Hwo can i solve the error in line 10
error is: Error using sub2ind
Too many output arguments.
clc;
clear all;
A=rand(6,6);
td = A;
pairidx = 0;
pairs = [];
while nnz(td(:) ~= 0 & ~isnan(td(:))) >= 2
std = size(td);
[maxd, maxidx] = max(td(:));
[maxr, maxc] = sub2ind(std, maxidx);
pairidx = pairidx + 1;
pairs(pairidx, :) = [maxr, maxc];
td(maxr, maxc) = nan;
td(maxc, maxr) = nan;
end
0 commentaires
Réponse acceptée
Star Strider
le 1 Fév 2019
You are using the inverse of the function you want.
Try this:
[maxr, maxc] = ind2sub(std, maxidx);
The max function returns the linear index of the maximum element in ‘td’, so you want to convert it to subscripts.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Discrete Math 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!