# replace values of x matrix for positions of y matrix where y=1

1 Ansicht (letzte 30 Tage)
Michal Sleszynski am 19 Okt. 2021
I have a matrix x that is 12x12double and i have a matrix y also 12x12double.
Its important to note that im running a loop and i will later need to generate bigger sized matrices so i need a code that will work for them as well.
but for now each column of x has these values
col.1
1. 3
2. 2.85
3. 2.55
4. 2.25
5. 1.95
6. 1.65
7. 1.35
8. 1.05
9. 0.75
10. 0.45
11. 0.15
12. 0
y is this
1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0 0
0 0 0 0 1 1 1 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1 1 1
i need the values of x to be equal to 1.5 for the positions of y where y = 1. how can i achieve this.
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Antworten (1)

Johannes Hougaard am 19 Okt. 2021
y = rand(33,33); % This is a y of random numbers between 0 and 1
x = round(rand(33,33)*0.7); % This is another x of random numbers between - rounded to either 1 or 0 as your y
y(x==1) = 1.5; % Assigns all y-values to 1.5 when x equals 1
##### 1 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Michal Sleszynski am 19 Okt. 2021
Thank you seems like i was overthinking it

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Matrix Indexing 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!

Translated by