replacing values in matrices under some condition
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Aleksandra Ksiezyk
am 12 Mär. 2021
Kommentiert: Aleksandra Ksiezyk
am 13 Mär. 2021
I have 2 matrixs: pa and win and i would like to create a matrix pTW where: if in pa is not 0 set to pTW a value from win.
pTW(pa ~= 0) = win ; this does not work
pa =
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
44 26 20 0 0 0 0 0 0 0 14 61
94 48 48 0 0 0 0 0 0 0 20 112
114 66 60 0 0 0 0 0 0 0 21 201
144 80 48 0 0 0 0 0 0 0 28 52
135 110 0 0 0 0 0 0 0 0 25 20
168 102 0 0 0 0 0 0 0 0 18 0
168 70 0 0 0 0 0 0 0 0 0 0
88 0 0 0 0 0 0 0 0 0 0 0
win =
0 0 0 0 0 0.0083 0.0188 0 0 0 0 0
0 0 0 0 0 0.0181 0.0444 0 0 0 0 0
0 0 0 0 0 0.0236 0.0363 0 0 0 0 0
0 0 0 0 0.0040 0.0333 0.0376 0.0108 0.0042 0 0 0
0 0 0 0 0.0323 0.0444 0.0255 0.0349 0.0139 0 0 0
0 0 0 0 0.0296 0.0431 0.0430 0.0672 0.0194 0 0 0
0 0 0 0 0.0349 0.0528 0.0430 0.0860 0.0264 0 0 0
0 0 0 0 0.0309 0.0569 0.0376 0.1008 0.0347 0 0 0
0 0 0 0.0097 0.0255 0.0569 0.0914 0.0726 0.0431 0 0 0
0 0 0 0.0208 0.0323 0.0514 0.0645 0.0699 0.0500 0 0 0
0 0 0 0.0278 0.0390 0.0500 0.0591 0.0484 0.0681 0.0202 0 0
0 0 0.0108 0.0319 0.0511 0.0500 0.0726 0.0672 0.0597 0.0376 0 0
0 0 0.0242 0.0361 0.0484 0.0417 0.0780 0.0591 0.0611 0.0336 0.0042 0
0 0 0.0242 0.0403 0.0685 0.0444 0.0618 0.0847 0.0667 0.0538 0.0083 0
0 0 0.0349 0.0472 0.0565 0.0528 0.0484 0.0659 0.0861 0.0524 0.0153 0
0 0 0.0242 0.0389 0.0484 0.0556 0.0349 0.0995 0.0722 0.0497 0.0097 0
0 0.0015 0.0349 0.0542 0.0565 0.0569 0.0363 0.0712 0.0667 0.0591 0.0222 0
0 0.0238 0.0323 0.0597 0.0538 0.0514 0.0457 0.0578 0.0667 0.0847 0.0569 0
0 0.0312 0.0282 0.0708 0.0726 0.0556 0.0309 0.0040 0.0556 0.0645 0.0681 0
0.0094 0.0268 0.0376 0.0653 0.0470 0.0417 0.0444 0 0.0514 0.0726 0.0556 0.0013
0.0282 0.0402 0.0403 0.0708 0.0470 0.0375 0.0457 0 0.0472 0.0645 0.0347 0.0148
0.0349 0.0312 0.0403 0.0653 0.0269 0.0333 0 0 0.0347 0.0820 0.0625 0.0269
0.0363 0.0417 0.0591 0.0542 0.0336 0.0236 0 0 0.0250 0.0699 0.0319 0.0954
0.0457 0.0417 0.0618 0.0542 0.0309 0.0125 0 0 0.0250 0.0484 0.0597 0.0793
0.0444 0.0461 0.0565 0.0500 0.0376 0.0042 0 0 0.0139 0.0618 0.0347 0.0712
0.0605 0.0476 0.0806 0.0403 0.0363 0 0 0 0.0083 0.0336 0.0556 0.0726
0.0645 0.0625 0.0511 0.0417 0.0336 0 0 0 0 0.0470 0.0389 0.0269
0.0538 0.0670 0.0457 0.0333 0.0228 0 0 0 0 0.0309 0.0653 0.0645
0.0457 0.0506 0.0430 0.0319 0 0 0 0 0 0.0336 0.0347 0.0215
0.0457 0.0565 0.0376 0.0264 0 0 0 0 0 0 0.0611 0.0645
0.0457 0.0685 0.0282 0.0208 0 0 0 0 0 0 0.0569 0.0242
0.0430 0.0595 0.0376 0.0083 0 0 0 0 0 0 0.0611 0.0672
0.0457 0.0491 0.0269 0 0 0 0 0 0 0 0.0722 0.0618
0.0538 0.0446 0.0376 0 0 0 0 0 0 0 0.0264 0.0376
0.0591 0.0387 0.0269 0 0 0 0 0 0 0 0.0194 0.0820
0.0632 0.0357 0.0323 0 0 0 0 0 0 0 0.0139 0.0753
0.0511 0.0327 0.0269 0 0 0 0 0 0 0 0.0097 0.0901
0.0484 0.0298 0.0161 0 0 0 0 0 0 0 0.0097 0.0175
0.0363 0.0327 0 0 0 0 0 0 0 0 0.0069 0.0054
0.0376 0.0253 0 0 0 0 0 0 0 0 0.0042 0
0.0323 0.0149 0 0 0 0 0 0 0 0 0 0
0.0148 0 0 0 0 0 0 0 0 0 0 0
0 Kommentare
Akzeptierte Antwort
the cyclist
am 12 Mär. 2021
Bearbeitet: the cyclist
am 12 Mär. 2021
You need to also select those specific elements from win, and also create pTW of the correct size, if it does not exist.
pTW = zeros(size(pa));
pTW(pa ~= 0) = win(pa ~= 0);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Operators and Elementary Operations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!