replace values of x matrix for positions of y matrix where y=1
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
- 3
- 2.85
- 2.55
- 2.25
- 1.95
- 1.65
- 1.35
- 1.05
- 0.75
- 0.45
- 0.15
- 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 commentaires
Réponses (1)
Johannes Hougaard
le 19 Oct 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
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!