For Loop Help Needed

1 回表示 (過去 30 日間)
Sarah
Sarah 2011 年 10 月 13 日
Hey guysss,
So I am trying to write a for loop to automatically detrend my signal until the "constant" value, or 0. I am using an updated detrend function that allows for higher order detrending rather than just linear.
%Detrend
Order.Max = 5;
X = 0:Order.Max - 1;
X = sort(X,'descend');
T1.Prc = detrend(T1.Sig1,Order.Max);
T2.Prc = detrend(T2.Sig1,Order.Max);
T3.Prc = detrend(T3.Sig1,Order.Max);
T4.Prc = detrend(T4.Sig1,Order.Max);
T5.Prc = detrend(T5.Sig1,Order.Max);
for Order.Low = X,
T1.Prc = detrend(T1.Prc,Order.Low);
T2.Prc = detrend(T2.Prc,Order.Low);
T3.Prc = detrend(T3.Prc,Order.Low);
T4.Prc = detrend(T4.Prc,Order.Low);
T5.Prc = detrend(T5.Prc,Order.Low);
end
I keep getting this error: ??? Error: File: fieldanalysisPART1.m Line: 18 Column: 10 Unexpected MATLAB operator.
Can you help me correct this? I essentially want the for loop to detrend the original signal T1.Sig1 with the highest order (for example, Order.Max = 5) and save it to T1.Prc. Then, I want the for loop to detrend T1.Prc with 4,3,2,1, and 0.

採用された回答

David Young
David Young 2011 年 10 月 13 日
It would help if you told us which is line 18, but I'm guessing it's probably the one that says:
for Order.Low = X,
since this will provoke the error message you get.
The reason is that you need to provide a simple variable name for the for-loop. You should try replacing the line above with these two lines:
for x = X
Order.Low = x;
(omitting also the extraneous comma). There may be other problems, but that will at least deal with the message you're getting now.
As a side point, instead of
X = 0:Order.Max-1;
X = sort(X, 'descend');
you could write
X = Order.Max-1 : -1 : 0;
  1 件のコメント
Sarah
Sarah 2011 年 10 月 13 日
That did solve my error, but I don't think it gives me the solution that I want. For example, I essentially want the for loop to be able to do this:
The highest order is 4:
% T1.Prc = detrend(T1.Sig1,4);
% T2.Prc = detrend(T2.Sig1,4);
% T3.Prc = detrend(T3.Sig1,4);
% T4.Prc = detrend(T4.Sig1,4);
% T5.Prc = detrend(T5.Sig1,4);
%
% T1.Prc = detrend(T1.Prc,3);
% T2.Prc = detrend(T2.Prc,3);
% T3.Prc = detrend(T3.Prc,3);
% T4.Prc = detrend(T4.Prc,3);
% T5.Prc = detrend(T5.Prc,3);
%
% T1.Prc = detrend(T1.Prc,2);
% T2.Prc = detrend(T2.Prc,2);
% T3.Prc = detrend(T3.Prc,2);
% T4.Prc = detrend(T4.Prc,2);
% T5.Prc = detrend(T5.Prc,2);
% T1.Prc = detrend(T1.Prc,'linear');
% T2.Prc = detrend(T2.Prc,'linear');
% T3.Prc = detrend(T3.Prc,'linear');
% T4.Prc = detrend(T4.Prc,'linear');
% T5.Prc = detrend(T5.Prc,'linear');
%
% T1.Prc = detrend(T1.Prc,'constant');
% T2.Prc = detrend(T2.Prc,'constant');
% T3.Prc = detrend(T3.Prc,'constant');
% T4.Prc = detrend(T4.Prc,'constant');
% T5.Prc = detrend(T5.Prc,'constant');
^where linear and constant are 1 and 0 respectively

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumeric Types についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by