Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
A(I) = B, the number of elements in B and I must be the same
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello,
I know I'm missing something fairly obvious, but I'm getting the error "A(I) = B, the number of elements in B and I must be the same" from a loop in my code:
for j = 1:num_footstrike
myMarkerCycle(j) = yy(start_fs(j):end_fs(j));
end
'num_footstrike' is a row vector, as are 'start_fs', 'end_fs' and 'yy'. Any thoughts?
댓글 수: 0
답변 (2개)
Evan
2013년 7월 2일
Assuming the sections of yy that you're assigning to myMarkerCycle are all the same size, try this:
for j = 1:num_footstrike
myMarkerCycle(j,:) = yy(start_fs(j):end_fs(j));
end
Otherwise, you might need to go some other route, such as using a cell array for myMarkerCycle instead of a matrix.
댓글 수: 2
Evan
2013년 7월 2일
No problem!
As for the cell array, they have their advantages and disadvantages. They allow you to store multiple datatypes and (more relevant to your case) arrays of variable size in a single array. However, if you end up with very large cell arrays or lots of operations on the cells, you can suffer performance losses and large memory use.
If you for some reason ran into either of these problems, there's one other way to create your array, but it would require padding your rows with zeros to make them all the same length. If you know that none of your data will be zero, this wont be a problem, but if zeros are a possibility, this wouldn't be a very convenient route.
Jan
2013년 7월 3일
As Evan has pointed out already, this is the method to store the vectors in a cell:
myMarkerCycle = cell(1, num_footstrike)
for j = 1:num_footstrike
myMarkerCycle{j} = yy(start_fs(j):end_fs(j));
end
This is clean and efficient when num_footstrikes is small, e.g. < 10'000. For large arrays it is worth to consider, if the current storage method isn't the most efficient solution already: A dense data vector yy and two index vectors start_fs and end_fs.
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!