how toggle % from matrix?
per=5;
a=magic(4)
i want to toggle from each element per (5%)

 채택된 답변

Star Strider
Star Strider 2023년 9월 30일

1 개 추천

Perhaps this —
per=5;
a=magic(4)
a = 4×4
16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1
apr = a*(1-0.05) % 95% Of The Value
apr = 4×4
15.2000 1.9000 2.8500 12.3500 4.7500 10.4500 9.5000 7.6000 8.5500 6.6500 5.7000 11.4000 3.8000 13.3000 14.2500 0.9500
apr = a*0.05 % 5% Of The Value
apr = 4×4
0.8000 0.1000 0.1500 0.6500 0.2500 0.5500 0.5000 0.4000 0.4500 0.3500 0.3000 0.6000 0.2000 0.7000 0.7500 0.0500
.

댓글 수: 4

shamal
shamal 2023년 9월 30일
편집: shamal 2023년 9월 30일
ok but i want to use 5% and not: (1-5/100)....I thought there was a more practical way with matlab
I could not tell if you wanted to calculate 5% or reduce it by 5% (so calculating 95%).
This produces 5%
format short g
a=magic(4)
a = 4×4
16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1
per=5;
apr = a*per/100 % 5% Of The Value
apr = 4×4
0.8 0.1 0.15 0.65 0.25 0.55 0.5 0.4 0.45 0.35 0.3 0.6 0.2 0.7 0.75 0.05
I doubt that there is any other way to calculate it.
.
shamal
shamal 2023년 9월 30일
okk thank
Star Strider
Star Strider 2023년 9월 30일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

질문:

2023년 9월 30일

댓글:

2023년 9월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by