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 Kommentare

madhan ravi
madhan ravi am 6 Aug. 2019
You say you have a highest number , do you mean a threshold value?
karishma koshy
karishma koshy am 6 Aug. 2019
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
madhan ravi
madhan ravi am 6 Aug. 2019
a=[1 2 3 0 4 5 0];
a(~a) = max(a)+(1:nnz(~a))
Guillaume
Guillaume am 6 Aug. 2019
@madhan,can you write that as an answer? I don't think it can be done any simpler.
madhan ravi
madhan ravi am 6 Aug. 2019
@Guillaume: Done :)

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

madhan ravi
madhan ravi am 6 Aug. 2019

2 Stimmen

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

Weitere Antworten (1)

Joel Handy
Joel Handy am 6 Aug. 2019

0 Stimmen

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 Kommentar

karishma koshy
karishma koshy am 6 Aug. 2019
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

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by