Changing values of martix in particular column
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Wiktoria Bukowska
am 26 Dez. 2019
Beantwortet: Star Strider
am 26 Dez. 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 Kommentare
Akzeptierte Antwort
Star Strider
am 26 Dez. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Multidimensional Arrays 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!