Changing values of martix in particular column
1 view (last 30 days)
Show older comments
Wiktoria Bukowska
on 26 Dec 2019
Answered: Star Strider
on 26 Dec 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 Comments
Accepted Answer
Star Strider
on 26 Dec 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 Comments
More Answers (0)
See Also
Categories
Find more on Multidimensional Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!