Why am I getting "Subscripted assignment dimension mismatch."

2 visualizaciones (últimos 30 días)
Alex
Alex el 29 de Nov. de 2018
Editada: Ken Atwell el 3 de En. de 2019
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

Respuesta aceptada

Ken Atwell
Ken Atwell el 30 de Nov. de 2018
Editada: Ken Atwell el 3 de En. de 2019
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 comentarios
Walter Roberson
Walter Roberson el 1 de Dic. de 2018
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 el 1 de Dic. de 2018
Yes, I use R2010A. This works for initializing the string vector. Thank you.
h = cell(1,29);

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by