Why am I getting "Subscripted assignment dimension mismatch."

조회 수: 2 (최근 30일)
Alex
Alex 2018년 11월 29일
편집: Ken Atwell 2019년 1월 3일
Hello,
I keep getting this error when I run the code on a certain dataset. but have used this code before without problems. For some reason it does not work past the second iteration.
for k=1:29
h(k,:) =sprintf('aircraft at %3.4f degrees latitude', parnam{1,k}.data(1,1)) ;
end
Untitled.png

채택된 답변

Ken Atwell
Ken Atwell 2018년 11월 30일
편집: Ken Atwell 2019년 1월 3일
It looks like you're trying to create a 2D matrix of char(acter)s. For this to work, each char vector needs to be exactly the same length. If you are on a recent-ish version of MATLAB, a vector of string might serve you better:
h = strings(1,29);
for k=1:29
h(k) =sprintf('aircraft at %3.4f degrees latitude', parnam{1,k}.data(1,1)) ;
end
  댓글 수: 3
Walter Roberson
Walter Roberson 2018년 12월 1일
You do not have "a recent-ish version of MATLAB".
h = cell(1,29);
for k=1:29
h{k} = sprintf('aircraft at %3.4f degrees latitude', parnam{1,k}.data(1,1)) ;
end
Alex
Alex 2018년 12월 1일
Yes, I use R2010A. This works for initializing the string vector. Thank you.
h = cell(1,29);

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by