How do you write a loop for a variable that will list 6 rows but you want the equation to apply for those 6 rows and 30 rows after each of them

조회 수: 1 (최근 30일)
the variable "RA4" contains 6 rows that indicate where a perturbation starts.
RA4 = 5721, 51164, 69680, 98014, 118377, 130204.
I am trying to write a loop that will apply the
XError equation -> abs(COMArray(:,1))-abs(New_COM(:,1));
to each of those RA4 rows and the next 30 for each. Meaning (5721:5751), etc. How can I write that?
  댓글 수: 1
David Hill
David Hill 2022년 8월 2일
Hard to understand without an example. Not sure what you mean by applying the XError equation to each row.
abs(COMArray(:,1))-abs(New_COM(:,1));%this looks like it is applying to a column
%RA4(5721,:) would be the row, take that row (I don't know the size of the
%row) and apply it how to the XError equation?

댓글을 달려면 로그인하십시오.

답변 (1개)

dpb
dpb 2022년 8월 3일
nAddLines=30;
for i=1:numel(RA4)
ix1=RA4(i);
ix2=ix1+nAddLines;
XError(?)=abs(COMArray(ix1:ix2,1))-abs(New_COM(ix1:ix2,1));
end
You'll have to have some indexing expression to compute a place to put the results -- and how to keep track of which part goes where...that's that the "?" placeholder is for--there's where you need an expression -- or you could just have a cell array each of which cells contains the results for each iteration as the quick 'n dirty way out.
The above applies the calculation only to a first column of some array as in your sample code snippet.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by