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에서 Multidimensional Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!