Displaying Specific Rows with Non-zero values
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Taner Cokyasar
le 8 Juil 2016
Commenté : Star Strider
le 8 Juil 2016
I created the following code to create variable names for my solution (Zvalues) to an MILP problem. (Zvalues are binary)
[Z1,Z2] = meshgrid(1:i,1:m);
Ztitle = [Z1(:),Z2(:),Zvalues(:)];
fprintf(' Z%d%d %d\n',Ztitle.')
It works pretty fine. When I run it, it gives the following response:
Z11 0
Z12 0
Z13 1
Z21 0
Z22 1
Z23 0
Z31 0
Z32 1
Z33 0
The "Zvalues" column includes answers for my variables. However, I want to only display nonzero values of Zvalues vector. So, for this case, I want to acquire following:
Z13 1
Z22 1
Z32 1
Thanks for any recommendation.
0 commentaires
Réponse acceptée
Star Strider
le 8 Juil 2016
Change your fprintf call to:
fprintf(' Z%d%d %d\n',Ztitle(Ztitle(:,3)~=0,:).')
That should do what you want.
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Multirate Signal Processing 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!