Help Needed with looping commands

I have two sets of column data (about 120 data points each), d(:,1) and c(:,2).
How do I use the 'for' and 'if' loop commands to evaluate the difference between each of the points in the variables (that is, say E = d - c) and then compare each of the outcome with an error value computed already to produce another column data of results less than the error benchmark.
Thank you.

回答 (1 件)

KSSV
KSSV 2020 年 9 月 17 日

0 投票

Just use:
E = d(:,1)-c(:,2) ;
You need not to use a loop.

4 件のコメント

inteli
inteli 2020 年 9 月 17 日
  1. How will I compare their differences with an error value and instruct it to output E and c values only of points less than the error value after the comparison.
KSSV
KSSV 2020 年 9 月 17 日
If A, B, C and D are arrays of same size.
E = A-B ; % get difference
idx = E<C ; % compare difference of A, B with elements in C
iwant = D(idx) ; % get elements in D by above comparison
inteli
inteli 2020 年 9 月 17 日
Thank you for the reply. Actually, I needed the program to output E and c values at any point/points of detection showing less than the error value.
KSSV
KSSV 2020 年 9 月 17 日
You can do what I have shown above right? Do the comparison, get the logical indices and pick the points.

この質問は閉じられています。

質問済み:

2020 年 9 月 17 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by