필터 지우기
필터 지우기

Displaying Specific Rows with Non-zero values

조회 수: 2 (최근 30일)
Taner Cokyasar
Taner Cokyasar 2016년 7월 8일
댓글: Star Strider 2016년 7월 8일
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.

채택된 답변

Star Strider
Star Strider 2016년 7월 8일
Change your fprintf call to:
fprintf(' Z%d%d %d\n',Ztitle(Ztitle(:,3)~=0,:).')
That should do what you want.
  댓글 수: 2
Taner Cokyasar
Taner Cokyasar 2016년 7월 8일
Thank you very much Star Strider.
Star Strider
Star Strider 2016년 7월 8일
My pleasure.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by