필터 지우기
필터 지우기

IndexingProblem

조회 수: 1 (최근 30일)
Stephen Molnar
Stephen Molnar 2012년 6월 8일
I have a macro that has an indexing problem.
CartridgeID
i = 1,length(allData);
Cart_ID(i) = allData(i).CartridgeID;
end
allData is a struct which contains allData(1,1).CartridgeID which is a 24 digit integer
An attempt to execute the above results in:
i =
1
Subscripted assignment dimension mismatch.
>>
Obviously an indexing problem, but I can't seem to find a solution.

답변 (1개)

Walter Roberson
Walter Roberson 2012년 6월 8일
Without a loop:
Card_ID = [allData.CartridgeID]
With a loop, you will need a "for" statement such as
for i = 1 : length(allData)
Notice the colon instead of comma, and notice the "for". The code you had assigns 1 to i, displays the result, calculates length(allData) and throws away the result of that calculation.
How did you manage to get a 24 digit integer? The maximum integer for uint64 is only 20 digits. Perhaps the value is not really a 24 digit integer, but is instead (e.g.) a string? If it is then you need to store it to multiple output locations:
for i = 1 : length(allData)
Cart_ID(i,:) = allData(i).CartridgeID;
end

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by