Create a matrix and a map of Hydrologic Soil Group values using integer or character values
Show older comments
I want to create a matrix and a map of Hydrologic Soil Group (HSG) values using integer or character values. I have a vector of 8853x1 with the HSG letters (A, B, C or D) for different locations in St. Croix island (USVI). I want to produce a 102x263 matrix with those letters, using different scripts that I have available. The problem is that Matlab doesn't let me produce a matrix with letters or character values (char format). The thing is, if I use numbers instead of letters (1, 2, 3 and 4), the matrix that is produced has all the numbers in double or float format, with decimal digits, and not whole numbers or integers.. But when I converted the vector to integer format, matlab doesn't produce a matrix from that vector. I will use this matrix to plot a map of the island showing different colors according to the HSG values or letters. How can I produce a matrix and a map with integer and/or character values using a 8853x1 vector? Should I just round up the numbers in the matrix to the nearest whole number?
Answers (1)
MATLAB does indeed allow you to produce a character matrix, with those characters. However, I assume you have scattered data, with measurements taken not on a grid. You will then want to interpolate onto the desired grid. I'll make up some scattered data, and some locations.
HSGmeas = char(randi([0,3],20,1) + 'A');
HSGxy = rand(20,2);
table(HSGxy,HSGmeas)
How will you then interpolate them onto a grid? Start with scatteredInterpolant. You will want to use linear interpolation, then round the result, and convert to character.
Subtracting 'A' below converts the letters into the integers [0,1,2,3]. As well, note that I use 'nearest' to prevent dangerous things happening outside of the convex hull of your data.
interp = scatteredInterpolant(HSGxy(:,1),HSGxy(:,2),HSGmeas - 'A','linear','nearest');
[xgrid,ygrid] = meshgrid(linspace(0,1,100));
ROUND the result. Do not round up.
zgrid = round(interp(xgrid,ygrid));
surf(xgrid,ygrid,zgrid)
char(zgrid + 'A')
Categories
Find more on Agriculture in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!