Array of Struct: Index exceeds matrix dimensions

조회 수: 1 (최근 30일)
pamela sulis
pamela sulis 2015년 10월 27일
편집: pamela sulis 2015년 10월 27일
Hi! I have a problem with an array of struct: I have an array that includes 106 struct. I want to convert string in number. If I use the function datevec on a single struct I have not problems; on the contrary when I want to apply the function datevec to all the structs in the array with a for cycle, the code generate an error: 'Index exceeds matrix dimensions'
for i=1:106
date=datevec(s(1,i).locs(:,1));
% Data di inizio rilevazione
dateStart=datevec(s(1,i).places.startdate(:,1));
% Data fine rilevazione
dateEnd=datevec(s(1,i).places.endate(:,1));
end
I don't understand what is my error! Maybe I have to pre-allocate date, dateStart and dateEnd like struct?

답변 (1개)

Thorsten
Thorsten 2015년 10월 27일
편집: Thorsten 2015년 10월 27일
Maybe you defined datevec as a variable? Please check using
which datevec
And does s always contain 106 elements? To make the code more robust you can use
for i = 1:size(s,2)
  댓글 수: 1
pamela sulis
pamela sulis 2015년 10월 27일
no, no datavec is not a variable... it is a matlab function. Thanks for the second suggest! I modify the code

댓글을 달려면 로그인하십시오.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by