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 Center および File ExchangeStress and Strain についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by