Why am I getting "Subscripted assignment dimension mismatch."

1 次查看(过去 30 天)
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