Extract first row from cell arrays

9 visualizaciones (últimos 30 días)
BN
BN el 11 de Abr. de 2020
Comentada: BN el 11 de Abr. de 2020
Hey all, I have a 1 x 3 cell, which contains tables. In each table there are a lat and lon columns, I want to extract the first row of these columns from each table and store them below each other in an array. I thought about unique function but since there is just an example and my original data has many points with the same latitude and different longitude and vice versa it's not applicable in this case.
BTW here is my try:
for i = 1:numel(test)
lat(i) = test{i}(1,3);
lon(i) = test{i}(1,4);
LATandLON = (lat(i), lon(i))
end
Again since the original data set is really huge and maybe different column's number, I would like to avoid hard coding but I don't know how to do this in this case.
Thank you

Respuesta aceptada

the cyclist
the cyclist el 11 de Abr. de 2020
Editada: the cyclist el 11 de Abr. de 2020
The following will give a 3-element cell array, where each cell has a 360x2 numeric array with the latitude and longitude vectors:
latAndLon = cellfun(@(x)[x.lat x.lon],test,'UniformOutput',false);
This code gives the same result as
for i = 1:numel(test)
latAndLon{i} = [test{i}.lat, test{i}.lon]
end
which might be easier to understand.
  6 comentarios
the cyclist
the cyclist el 11 de Abr. de 2020
If that's the output you want, I guess it's right. :-)
You could test on a different input to be sure.
BN
BN el 11 de Abr. de 2020
Thank you so much

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by