Problems with function num2str
5 views (last 30 days)
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.
dpb on 21 Oct 2021
Edited: dpb on 21 Oct 2021
Well, having a file helps (as always)...
>> DatosInfo=ncinfo('..\Answers\DatosMarzoD1.nc') % see what's in the file...
struct with fields:
Dimensions: [1×3 struct]
Variables: [1×9 struct]
Attributes: [1×2 struct]
>> DatosInfo.Variables % which variables are in there????
1×9 struct array with fields:
>> DatosInfo.Variables.Name % and what are their names?
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--
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.
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
legend("TP @ HR: "+h,'Location',"best")
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.
More Answers (1)
Steven Lord on 19 Oct 2021
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])