Hi I am having a hard time using the getfield. It says there is an error.

2 ビュー (過去 30 日間)
Megan Mirkhanian
Megan Mirkhanian 2019 年 12 月 18 日
コメント済み: Walter Roberson 2019 年 12 月 19 日
The error says to use dynamic field names with structures instead of GETFIELD.
%%
%%% load the latitude and longitude files (FYI, for some reason the data is
%%% flipped so that Lat is on the horizontal axis and Lon is on the
%%% vertical.
latStruct = load('L:\Flow ecology and climate change_ES\FromKelly_HECHMS_models\PostProcess_PrecipData_AlexHall\Matlabcode\LatLons\surface_lat2.mat');
latField = fieldnames(latStruct);
%lat = getfield(latStruct,string(latField(1,1)));
lat = getfield(latStruct,string(latField(1,1))); %#ok<*GFLD>
lonStruct = load('L:\Flow ecology and climate change_ES\FromKelly_HECHMS_models\PostProcess_PrecipData_AlexHall\Matlabcode\LatLons\surface_lon2.mat');
lonField = fieldnames(lonStruct);
lon = getfield(lonStruct,string(lonField(1,1)));

回答 (1 件)

Ridwan Alam
Ridwan Alam 2019 年 12 月 19 日
lat = getfield(latStruct,latField{1});
  1 件のコメント
Walter Roberson
Walter Roberson 2019 年 12 月 19 日
You are using a fairly old version of MATLAB. Anywhere you see string() used in code you will need to rewrite the code. string in your very old version is not compatible with string in modern versions.
Also, after string was introduced in R2016b, it took a couple of releases before it could be used in getfield()

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeJSON Format についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by