loop for subtracting values

1 view (last 30 days)
Iffat Arisa
Iffat Arisa on 18 Nov 2021
Commented: Steven Lord on 29 Nov 2021
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

Accepted Answer

Walter Roberson
Walter Roberson on 18 Nov 2021
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 Comments
Iffat Arisa
Iffat Arisa on 29 Nov 2021
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 on 29 Nov 2021
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

Sign in to comment.

More Answers (0)

Categories

Find more on Physics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!