MATLAB Answers

how to read data from characters?

5 views (last 30 days)
Lilya on 18 Dec 2018
Commented: Lilya on 19 Dec 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]);
Any help will be appreciated :(
  1 Comment
Stephen on 18 Dec 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];

Sign in to comment.

Accepted Answer

Stephen on 18 Dec 2018
Edited: Stephen on 18 Dec 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 =;
S(k).lon = T.lon;
S(k).sst = T.sst;
If the imported data have compatible sizes you could concatenate them into arrays, e.g.:
lat = []
lon = [S.lon]
Lilya on 19 Dec 2018
Thanks a lot !!! it works

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by