# Create a matrix and a map of Hydrologic Soil Group values using integer or character values

2 vues (au cours des 30 derniers jours)
Luis le 5 Mai 2024
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?
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponses (1)

John D'Errico le 6 Mai 2024
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)
ans = 20x2 table
HSGxy HSGmeas ____________________ _______ 0.94732 0.62392 C 0.97753 0.55289 D 0.98256 0.46539 C 0.59896 0.59335 A 0.6421 0.78152 D 0.017624 0.58181 A 0.21225 0.14788 A 0.050551 0.31561 B 0.64462 0.88462 B 0.049427 0.436 A 0.99362 0.44818 D 0.57008 0.98742 D 0.68726 0.82904 C 0.71384 0.9056 B 0.48322 0.12337 A 0.40099 0.047118 B
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')
ans = 100x100 char array
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Scatter Plots dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by