how to read data from characters?

3 visualizaciones (últimos 30 días)
Lilya
Lilya el 18 de Dic. de 2018
Comentada: Lilya el 19 de Dic. de 2018
Hi all,
I am trying to read the variables from the list of characters those are saved as .mat file 'attached screenshot.' each of those .mat file has sst, lat, lon. I could not find a proper way to get the data by using the for loop.
for N = 1:nfiles;
filename = [flist(N).name];
disp(['Processing ', flist(N).name]);
end
Any help will be appreciated :(
thanks
  1 comentario
Stephen23
Stephen23 el 18 de Dic. de 2018
Note that square brackets are a concatenation operator in MATLAB, so they are completely redundent on this line (you are not concatenating anything):
filename = [flist(N).name];

Iniciar sesión para comentar.

Respuesta aceptada

Stephen23
Stephen23 el 18 de Dic. de 2018
Editada: Stephen23 el 18 de Dic. de 2018
D = 'path of the directory where those files are saved';
S = dir(fullfile(D,'erdMH*.mat'));
for k = 1:numel(S)
T = load(fullfile(D,S(k).name));
S(k).lat = T.lat;
S(k).lon = T.lon;
S(k).sst = T.sst;
end
If the imported data have compatible sizes you could concatenate them into arrays, e.g.:
lat = [S.lat]
lon = [S.lon]
  4 comentarios
Stephen23
Stephen23 el 19 de Dic. de 2018
Editada: Stephen23 el 19 de Dic. de 2018
"I want the final sst matrix separated"
I do not know what a "separated" matrix is. You can access the imported sst arrays:
  • directly from the non-scalar structure S, or
  • concatenating together (as I showed in my answer), or
  • by putting them into a cell array:
C = {S.sst}
Lilya
Lilya el 19 de Dic. de 2018
Thanks a lot !!! it works

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by