loop for subtracting values

1 次查看(过去 30 天)
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 中查找有关 Physics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by