Why am I getting "Subscripted assignment dimension mismatch."

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 日

1 投票

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 件のコメント

Alex
Alex 2018 年 11 月 30 日
編集済み: Alex 2018 年 11 月 30 日
Thank you, but this gives an error
h = strings(1,29);
??? Attempt to execute SCRIPT strings as a function:
C:\Program Files (x86)\MATLAB\R2010a Student\toolbox\matlab\strfun\strings.m
I read the documentation and found I just needed curly braces. This works.
for k=1:29
h{k} =sprintf('aircraft at %3.4f degrees latitude', parnam{1,k}.data(1,1)) ;
end
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 件)

カテゴリ

タグ

質問済み:

2018 年 11 月 29 日

編集済み:

2019 年 1 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by