# Index Exceeds Matrix Dimensions

3 visualizaciones (últimos 30 días)
Jake el 24 de Dic. de 2019
Comentada: Jake el 26 de Dic. de 2019
Hello,
Apologies in advance for posting a common error/problem but I couldn't find relevant solutions in other simliar threads.
So I'm trying out this code which I found online and it gives the above mentioned error at:
srdata=struct('data',[],'Longitude',[],'Lattitude',[],'altitude',[],'Description',[]);
[m,n] = size(data)
srdata.data = data(:,1);
srdata.Longitude = data(:,2);
srdata.Lattitude = data(:,3);
srdata.altitude = data(:,4);
for i=1:m
srdata.Description{i,1} = txt{i,5};
end
error line points at "srdata.Description{i,1} = txt{i,5};" and says "Index Exceeds Matrix Dimensions".
I wanted to know why am I getting this and how to fix this, if possible.
P.S: sample.xlsx is something like this.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Andrei Bobrov el 24 de Dic. de 2019
T.Properties.VariableNames = {'data','Longitude','Lattitude','altitude','Description'};
srdata = table2struct(T);
##### 3 comentariosMostrar 1 comentario más antiguoOcultar 1 comentario más antiguo
Andrei Bobrov el 24 de Dic. de 2019
m = size(data,1);
srdata=struct('data',cell(m,1),'Longitude',[],'Lattitude',[],'altitude',[],'Description',[]);
for i = 1:m
srdata(i).data = data(i,1);
srdata(i).Longitude = data(i,2);
srdata(i).Lattitude = data(i,3);
srdata(i).altitude = data(i,4);
srdata(i).Description = txt{i};
end
Jake el 26 de Dic. de 2019
Thank you so much!

Iniciar sesión para comentar.

### Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by