loop for subtracting values

조회 수: 2 (최근 30일)
Iffat Arisa
Iffat Arisa 2021년 11월 18일
댓글: Steven Lord 2021년 11월 29일
I am trying to get subtraction from the strain data of all channels to the strain data of channel 1. But the following codes give me the subtraction only from channel 2 to channel 1. I don't get the other channels. Please help me to correct the codes.
data1 = Dasdata.Strain(channels,1)';
for i = 2:53
data2 = Dasdata.Strain(channels,i);
y = data2-data1;
plot(y)
end

채택된 답변

Walter Roberson
Walter Roberson 2021년 11월 18일
data1 = Dasdata.Strain(channels,1)';
for i = 2:53
data2 = Dasdata.Strain(channels,i);
y = data2-data1;
plot(y, 'DisplayName', "channel " + i);
hold on
end
hold off
legend show
  댓글 수: 2
Iffat Arisa
Iffat Arisa 2021년 11월 29일
Thanks.
I have 53 columns and 40000 rows in a matrix. I need to subtract from column 2 to column 1, column 3 to column 1,.. To get all columns including all elements - column 1, which Matlab command should be used?
Steven Lord
Steven Lord 2021년 11월 29일
Use implicit expansion.
A = randi(10, 5, 10) % sample data between 1 and 10
A = 5×10
9 5 6 10 5 5 1 5 1 7 9 5 9 4 4 1 10 3 1 6 8 9 7 1 1 2 1 7 7 8 3 10 6 7 10 7 5 6 10 8 3 3 10 10 1 10 7 10 7 10
B = A - A(:, 1)
B = 5×10
0 -4 -3 1 -4 -4 -8 -4 -8 -2 0 -4 0 -5 -5 -8 1 -6 -8 -3 0 1 -1 -7 -7 -6 -7 -1 -1 0 0 7 3 4 7 4 2 3 7 5 0 0 7 7 -2 7 4 7 4 7

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Stress and Strain에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by