필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

A(I) = B, the number of elements in B and I must be the same

조회 수: 1 (최근 30일)
Amanda
Amanda 2013년 7월 2일
마감: MATLAB Answer Bot 2021년 8월 20일
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?

답변 (2개)

Evan
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
Amanda
Amanda 2013년 7월 2일
Ah, I see. The sections of yy are slightly varied in their lengths. So you would recommend using a cell array? I'm not familiar with how those work, but I'll look into it. Thanks!
Evan
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
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.

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by