필터 지우기
필터 지우기

Extracting n elemnts of an array

조회 수: 1 (최근 30일)
Nikolas Spiliopoulos
Nikolas Spiliopoulos 2017년 1월 31일
답변: John D'Errico 2017년 1월 31일
Hi,
II have an array with dimensions [5568X1] and I want to extract every 48 values and put it in a different array (so 5568/48=116 arrays).
I have already created a cell(116,1), and probably i need an k=1:116
do you know how can I do this?
thanks
Nikolas

채택된 답변

John D'Errico
John D'Errico 2017년 1월 31일
Why do you think that you need to create 116 different arrays? This is a terrible idea, and one every novice programmer thinks they need to do. You don't even need to create a cell array of vectors. Instead, learn to use an array, instead of many vectors. Then a simple call to reshape will suffice.
b = rand(5568,1); % just something random to show you how it works
a = reshape(b,48,116);
size(a)
ans =
48 116
So now you can access any one of those vectors as simply an index operation. So if you want to use the third such vector, do this:
a(:,3)
There is absolutely NO need to use a cell array here, although it is something of value in many circumstances.

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by