필터 지우기
필터 지우기

Using while loop to analyze cell array

조회 수: 4 (최근 30일)
Benjamin
Benjamin 2012년 7월 6일
Let's say I have a cell array that is 1x10000. The variable name given to the dataset is data.
So i want to be able to use a cell in the array, the cell before, and the cell after the center cell. so something along these lines:
cell before = n-1
cell after = n+1
So in the while loop I want to do some thing like this:
while n < length(data)
n = data;
before = n-1;
after = n+1;
eq = (abs(n - ((before+after)/2))/((before+after)/2))*100;
end
I dont believe this is entirely correct, any input on what needs to be changed?

채택된 답변

per isakson
per isakson 2012년 7월 7일
편집: per isakson 2012년 7월 11일
Why a cell array of numeric data rather than a numeric array? Many questions are about removing loops. Why a while-loop?
This is more like the Matlab way:
N = 1000;
data = rand( N, 1 );
tmp = (data(1:end-2)+data(3:end))/2;
out = 100*abs( data(2:end-1) - tmp )./ tmp;
plot( out )
.
--- Another example ---
N = 100;
n = transpose( (1:N) );
data = sin( 2*pi*n/N );
before = [ nan; data( 1 : end-1 ) ];
after = [ data( 2 : end ); nan ];
plot( n, [ before, data, after ], '.' )
tmp = ( before + after ) / 2;
out = 100*abs( data - tmp )./ tmp; % eq is the name of a function
plot( n, data-tmp, '.' )
plot( n, out, '.' )
.
See "Evaluate Subsections of Files Using Code Cells" in the documentation and evaluate the cells one at a time.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by