Changing values of martix in particular column
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Wiktoria Bukowska
il 26 Dic 2019
Risposto: Star Strider
il 26 Dic 2019
Hi, I have a matrix of 366 rows and 35 columns. I would like to change values in 35th column (for every row) in this following way: if it equals 1 leave like it is, if there is any other value - change to 0. I was thinking about using for loop, but I'm very begginer in programming and wasn't able to write a good code.
0 Commenti
Risposta accettata
Star Strider
il 26 Dic 2019
Try this:
M = randi(9, 366, 35); % Create Matrix
Original = M(1:10,35); % Temporary, Delete Later
newM = M; % New Version Of ‘M’
newM(:,35) = M(:,35) == 1; % Change Column #35
Result = [Original, newM(1:10,35)] % Desired Result
producing (for example in this run):
Result =
3 0
2 0
5 0
1 1
7 0
9 0
5 0
4 0
1 1
5 0
The ‘Result’ matrix is simply to display the original (first column) and the transformed version (second colukmn). The other columns are unchanged.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Multidimensional Arrays in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!