필터 지우기
필터 지우기

Reallocate values in matrix to even the values

조회 수: 1 (최근 30일)
JL
JL 2019년 7월 24일
댓글: JL 2019년 8월 8일
I have this original traffic matrix
Y = [0.00 10.0 10.0 10.0;
10.0 0.00 10.0 10.0;
10.0 10.0 0.00 10.0;
10.0 10.0 10.0 0.00;]
And when one of them becomes 0, for example,
Y = [0.00 0.00 10.0 10.0;
0.00 0.00 10.0 10.0;
10.0 10.0 0.00 10.0;
10.0 10.0 10.0 0.00;]
I want to guarantee that the 0.00 is always 5.00
Y = [0.00 5.00 10.0 10.0;
5.00 0.00 10.0 10.0;
10.0 10.0 0.00 10.0;
10.0 10.0 10.0 0.00;]
but because of that some of the values decreases
Y = [0.00 5.00 5.00 10.0;
5.00 0.00 10.0 5.00;
5.00 10.0 0.00 10.0;
10.0 5.00 10.0 0.00;]
I was wondering if there is code to do this efficiently for this part? The second part will be, can I even the values further? For example below
Y = [0.00 5.00 7.50 7.50;
5.00 0.00 10.0 5.00;
7.50 10.0 0.00 7.50;
7.50 5.00 7.50 0.00;]

채택된 답변

Andrei Bobrov
Andrei Bobrov 2019년 7월 24일
n = size(Y);
lo = ~eye(n);
Y(lo) = max(Y(lo),5);
  댓글 수: 2
JL
JL 2019년 7월 24일
Thanks Andrei
The answer gave me as
Y = [0.00 5.00 10.000 10.0;
5.00 0.00 10.0 10.0;
10.00 10.0 0.00 10.0;
10.0 10.0 10.0 0.00;]
instead of this below, when we guarantee it from 0 to 5.0, the values in the matrix also decreases
Y = [0.00 5.00 5.00 10.0;
5.00 0.00 10.0 5.00;
5.00 10.0 0.00 10.0;
10.0 5.00 10.0 0.00;]
JL
JL 2019년 8월 8일
Hi Andrei, I have another intetesting problem, was wondering if you are interested to take a look - here is the link to the question https://uk.mathworks.com/matlabcentral/answers/475460-sharing-values-of-elements-in-a-matrix

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by