Error field assignment to a non structured array

When running this script I get the error, "Field Assignment to a non-structured array" on line 32, "w.dir = m {6} ; ". I am new to matlab, but I've used this same code before to open a different file with different variable names. I think the issue may be in my textscan command? Any thoughts from the pros?
function w = read_met_station(met_file)
met_file = '\\file\weather_data.txt' ;
fid = fopen(met_file) ;
if fid == -1
error('Error. \nFile can not be opened. Check path.') ;
return
end
w = textscan(fid,'%5s %*1c %f %*1c %f %*1c %f %*1c %f %*1c %f %*1c %f %*1c %f %*1c %f %*1c %f %*1c %f %*1c %f %*1c %f %*1c %f %*1c %f %*1c %f %*1c %f %*1c %f %*1c %f','HeaderLines',1) ;
station_num = w{1} ;
year = w{2} ;
month = w{3} ;
day = w{4} ;
hour = w{5} ;
w.dir = w{6} ;
w.speed = w{7} ;
w.gustdir = w{8} ;
w.gustspd = w{9} ;
w.windrun = w{10} ;
w.rain = w{11} ;
w.tdry = w{12} ;
w.twet = w{13} ;
w.rh = w{14} ;
w.tmax = w{15} ;
w.tmin = w{16} ;
w.tgmin = w{17} ;
w.et10 = w{18} ;
w.rad = w{19} ;
w.dn = datenum(year,month,day,hour,zeros(size(hour))) ;

댓글 수: 4

What does this say:
>> whos w
Also read this link and fix your formatting, and attach your text file so people can try some code on it.
geog170
geog170 2017년 10월 25일
Thanks, I didn't realize that there was a formatting tool. I've attached a sample of the data as well. W is an arbitrary letter I used because it's a weather file.
KSSV
KSSV 2017년 10월 25일
YOur w is a class of cell..you are treating it as structure, which is not correct.
geog170
geog170 2017년 10월 25일
I ended up being able to fix it by changing all my "w." to "t." and updating the datenum to be (year,month,day). I'm not sure why it is having an issue with the hours.

댓글을 달려면 로그인하십시오.

 채택된 답변

KSSV
KSSV 2017년 10월 25일
편집: KSSV 2017년 10월 25일

0 개 추천

T = readtable(met_file) ;
or
T = fileread(met_file) ;

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Standard File Formats에 대해 자세히 알아보기

질문:

2017년 10월 25일

댓글:

2017년 10월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by