Changing values of martix in particular column
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Star Strider
2019-12-26
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!