Problems with function num2str
9 ビュー (過去 30 日間)
古いコメントを表示
Hi, I've got a variable that is (22x414x744 double) and when I use num2str it the variable converts to (1x308016 double) could anybody explain to me why this happens? And as I want to graffic it the variables is (latitud, longitud, time) how could i do it couse I would like to do a graffic durint time to see how evolvs.
21 件のコメント
dpb
2021 年 10 月 20 日
If you've got a file that is now relatively small, how about attaching it so somebody else can look at what the actual file content is? It would be interesting to see both file formats.
I, for one, have never had occasion to use either "in anger" so don't have any real experience...
採用された回答
dpb
2021 年 10 月 21 日
編集済み: dpb
2021 年 10 月 21 日
Well, having a file helps (as always)...
>> DatosInfo=ncinfo('..\Answers\DatosMarzoD1.nc') % see what's in the file...
DatosInfo =
struct with fields:
Filename: 'C:\Users\DPB\Documents\MATLAB\Answers\DatosMarzoD1.nc'
Name: '/'
Dimensions: [1×3 struct]
Variables: [1×9 struct]
Attributes: [1×2 struct]
Groups: []
Format: '64bit'
>> DatosInfo.Variables % which variables are in there????
ans =
1×9 struct array with fields:
Name
Dimensions
Size
Datatype
Attributes
ChunkSize
FillValue
DeflateLevel
Shuffle
>> DatosInfo.Variables.Name % and what are their names?
ans =
'longitude'
ans =
'latitude'
ans =
'time'
ans =
'u10'
ans =
'v10'
ans =
't2m'
ans =
'ssr'
ans =
'sp'
ans =
'tp'
>>
And, indeed, we find that we do have the corollary location and time variables as knew must have -- so let's load 'em into workspace--
>> lat=ncread('..\Answers\DatosMarzoD1.nc','latitude');
lon=ncread('..\Answers\DatosMarzoD1.nc','longitude');
t=ncread('..\Answers\DatosMarzoD1.nc','time');
tp=ncread('..\Answers\DatosMarzoD1.nc','tp');
>>
And now let's do something with them -- we'll plot every six hours as a surface plot -- will do as tiled arrangement to be compact for posting; a full figure for each would undoubtedly be more informative for real work; this is just illustrating pulling the data.
>> close,figure
tiledlayout('flow')
for h=0:6:24 % for the hours 0, 6, 12, ...
nexttile % make the next tile area ready
i=h+1; % arrays are 1-based, not 0-based
surf(lat,lon,tp(:,:,i)) % plot surf of this hour's data
ylabel('Longitude'),xlabel('Latitude')
legend("TP @ HR: "+h,'Location',"best")
end
produced
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/773768/image.jpeg)
That should give you a start on using the data.
I could not find the reference time definition at the ERA5 web site so I don't know how to convert the time vector to actual time at the moment; that's an exercise you'll have to figure out.
Also, the above is the raw, packed data; you'll need to apply the scaling/offset factors to turn it into the real data.
See all the details of using the data besides just the manipulation of the files at the web site, I don't have the time to be able to pursue it in more depth, sorry.
2 件のコメント
dpb
2021 年 10 月 21 日
Glad to help; sorry don't have the time to spare at the moment to try to dig into the data formatting in depth. There are descriptions at the web site for the unpacking, that'll be a pretty straightforward multiply/add operation it appears.
I don't know why it seemed so difficult to find out what the time reference is, but I couldn't seem to locate anything about it anywhere. I'm sure I must just be overlooking it.
その他の回答 (1 件)
Steven Lord
2021 年 10 月 19 日
If you want to convert a numeric array to an array of text where each element of the numeric array becomes its own element in the text array, I recommend using string.
A = [1, 2.5, -99; Inf, pi, NaN]
S = string(A)
You could use this in a call to the text function to display the strings on a figure.
[x, y] = meshgrid(1:3, [2 1]);
text(x(:), y(:), S(:))
axis([0 4 0 3])
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で NetCDF についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!