Create an Array of Vectors from Existing Vector
조회 수: 8 (최근 30일)
이전 댓글 표시
This is a silly question, but I am terrible with Matlab, which limits my usefulness in searching for help online. Any help would be greatly appreciated.
I have a vector that is 83000x1. I am trying to break it into 41 different vectors, each 2000x1. How can I create an array that has all of the data in it? I'd like it create a new v(i) for each iteration, that v being a vector of all of the data for that data set( i = 1, v = 1-2000)
This is what I've been trying to work with...
A = xlsread('Lab_A05_A_XD_15','B127:B83126');
for i = 1:41
b = 1+i*2000-2000;
c = 2000*i;
v{i} = {A(b):A(c)};
end
Thanks!
댓글 수: 0
답변 (1개)
Star Strider
2014년 11월 12일
The reshape function is your friend here.
If ‘V’ is your (83000x1) column vector, ‘M’ will be your data matrix that results from reshaping it:
V = [1:83000]';
N = 41*2000;
M = reshape(V(1:N),2000,[]);
댓글 수: 2
Star Strider
2014년 11월 12일
편집: Star Strider
2014년 11월 12일
My pleasure!
We need to know how many NaN values are in your data, and where they are to make this work. Also, are all your data 2000 elements long, or do they vary in length?
For the NaN problem, do this (again assuming ‘V’ is your vector, so make the appropriate substitution in the ‘Vdat’ and ‘Vnan’ assignments):
Vdat = find(~isnan(V)); % Find Data
dVdat = diff([0; Vdat]);
sVdat = [1; find(dVdat>1)];
pVdat = Vdat(sVdat); % Data Start Indices
Vnan = find(isnan(V)); % Find NaNs
dVnan = diff([0; Vnan]);
sVnan = find(dVnan>1);
pVnan = Vnan(sVnan); % NaN Start Indices
nVnan = size(Vnan); % Number of NaNs
This should tell us what we need to know to reshape your array, so please send along the results of: ‘pVdat’, ‘pVnan’, and ‘nVnan’. Note that what you want may not be possible if it turns out the rows of data aren’t the same length. That means a cell array which is not a problem, but could also mean that your data analysis could be a bit more difficult.
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!