Hi all I have got a table where I want to assign number bigger than the highest number already there in the table to the ones assigned zero. How can I do that.

댓글 수: 5

madhan ravi
madhan ravi 2019년 8월 6일
You say you have a highest number , do you mean a threshold value?
karishma koshy
karishma koshy 2019년 8월 6일
If I am having one of the column with 1 2 3 0 4 5 0 and I want it has 1 2 3 6 4 5 7.
Thank you
a=[1 2 3 0 4 5 0];
a(~a) = max(a)+(1:nnz(~a))
Guillaume
Guillaume 2019년 8월 6일
@madhan,can you write that as an answer? I don't think it can be done any simpler.
madhan ravi
madhan ravi 2019년 8월 6일
@Guillaume: Done :)

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

 채택된 답변

madhan ravi
madhan ravi 2019년 8월 6일

2 개 추천

a = [1 2 3 0 4 5 0];
a(~a) = max(a) + (1:nnz(~a))

추가 답변 (1개)

Joel Handy
Joel Handy 2019년 8월 6일

0 개 추천

Something like this?
table = randi([0 10],10,10);
tableMax = max(max(table));
table(table==0) = tableMax+1;
% Or Just
table(table==0) = Inf;

댓글 수: 1

karishma koshy
karishma koshy 2019년 8월 6일
If I am having one of the column with 1 2 3 0 4 5 0 and I want it has 1 2 3 6 4 5 7. How can I do that
Thank you

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

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2019년 8월 6일

댓글:

2019년 8월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by