필터 지우기
필터 지우기

change specific col and row in a matrix

조회 수: 3 (최근 30일)
muhammad faiz
muhammad faiz 2018년 8월 27일
댓글: Walter Roberson 2021년 11월 1일
Hi, let say i have matrix A=[20 40 60 70; 10 20 30 40; 60 50 20 10]. I want to change value in these location (e.g (2,2),(3,2),(1,4)) to 5 without having typing one by one to change the value.. how i can do that?
  댓글 수: 1
Tiasa Ghosh
Tiasa Ghosh 2018년 8월 27일
do you have a pattern for the specific locations?

댓글을 달려면 로그인하십시오.

채택된 답변

KSSV
KSSV 2018년 8월 27일
A=[20 40 60 70; 10 20 30 40; 60 50 20 10] ;
r = [2 3 1] ;
c = [2 2 1] ;
B = A ;
% Method 1 , use loop
for i = 1:length(r)
A(r(i),c(i)) = 5 ;
end
% Method 2, use indices
idx = sub2ind(size(A),r,c) ;
B(idx) = 5 ;

추가 답변 (1개)

Rita Barnabé
Rita Barnabé 2021년 11월 1일
편집: Walter Roberson 2021년 11월 1일
Hi, how do I change all the values in a specific column ?
%Original values
ecg = Data (:,6);
n = 9; % Number of bits of the channel (?)
VCC = 3; % Operating voltage
Gecg = 1000; % Sensor gain
ecg_volts = (ecg/(2^n)-1/2)*VCC/Gecg;
and now i want to change ecg to ecg_volts value

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by