How to trim down data in an array

조회 수: 29 (최근 30일)
Telema Harry
Telema Harry 2021년 11월 10일
댓글: Telema Harry 2021년 11월 10일
Hi,
I have a column vector containing 1000 element.
I really need to reduce the size of the vector to 100 to be able to use it further in my program.
The reduced data must contain the first and last element of the original vector.
My current code is shown below. It does not capture the last element.
Thanks for your help.
a = 1;
b = 200;
A = (b-a).*rand(1000,1) + a;
%
tt = floor(length(A)/10);
if tt == 0
tt = 1;
end
red_A = A(1:tt:end)

채택된 답변

Walter Roberson
Walter Roberson 2021년 11월 10일
tt = floor(linspace(1,lenth(A),100));
red_A = A(tt) ;

추가 답변 (1개)

KSSV
KSSV 2021년 11월 10일
a = 1;
b = 200;
A = (b-a).*rand(1000,1) + a;
x1 = 1:length(A) ;
x2 = linspace(1,length(A),100) ;
Anew = interp1(x1,A,x2) ;

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by