Borrar filtros
Borrar filtros

Maintaining figure when adding new data values?

1 visualización (últimos 30 días)
Olivia Wycklendt
Olivia Wycklendt el 28 de Nov. de 2017
Editada: Rik el 28 de Nov. de 2017
I have a code that I have been working on that is having a few issues. The figure should be equalateral, however, when I add new data values the code reverts back to an isosceles triangle. Any advice on how to fix this (and have the data points be where they're supposed to be, which is half the height that they are at now) would be appreciated!
Code is below:
%Input:
%sand: sand fraction [0..1], (nx1)
%clay: Clay fraction[0..1], (nx1)
%T: type of classification: 'usda'
%Varargin{1}: PLOT, BOOLEAN: 1: plots the usda texture triangle plus data
%points
%
%Output:
% SC: CellArray of soil class strings, (nx1)
% silt: Silt fraction [%], (nx1)
% SCINT: Array of soil class integers, (nx1)
% SC2: CellArray of soil class strings in short notation, e.g. S for SAND (nx1)
%
%Example:
%soil_classification(sand,clay, 'usda')
%soil_classification([0.5;0.3;0.1;0],[0.1;0.2;0.4;0.8], 'usda',1)
%--------------------------------------------------------------------------
%disp('-------------------------------------------------------------------')
%disp(' U S D A soil Classification ')
%disp('-------------------------------------------------------------------')
function [SC, silt, SCINT, SC2]=soil_classification(sand, clay, T,varargin)
if strcmp(T,'usda')==0
error('only usda defined so far...')
end
if isempty(sand)|isnan(sand)|min(sand)<0
error('wrong input: sand')
end
if isempty(clay)|isnan(clay)|min(clay)<0
error('wrong input: sand')
end
if max(sand)>1
sand=sand/100;
warning('sand is >1; ...divided by 100 to get fraction instead of %')
end
if max(clay)>1
clay=clay/100;
warning('clay is >1; ...divided by 100 to get fraction instead of %')
end
if max(sand+clay)>1
error('data inconsisent: (Clay + Sand)>1')
end
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
silt=1-sand-clay;
i=1;
for i=1:length(clay)
if (silt(i)+1.0*clay(i))<.15
SC{i,:}='SAND';
elseif ((silt(i)+.075*clay(i))>=.15)&((silt(i)+2*clay(i))<.3)
SC{i,:}='LOAMY SAND';
elseif (clay(i)>=0.07) & (clay(i)<=0.2) & (sand(i)>0.52) & ((silt(i)+2*clay(i))>=0.3)
SC{i,:}='SANDY LOAM';
elseif (clay(i)<0.07) & (silt(i) < 0.5) & ((silt(i)+2*clay(i))>=0.3)
SC{i,:}='SANDY LOAM';
elseif (clay(i)>=0.07) & (clay(i)<=0.27) & (silt(i)>=0.28) & (silt(i)<0.5) & (sand(i)<=0.52)
SC{i,:}='LOAM';
elseif ((silt(i)>=0.5) & clay(i)>=0.12 & clay(i)<0.27) | (silt(i)>=0.5 & silt(i)<0.8 & clay(i)<0.12)
SC{i,:}='SILT LOAM';
elseif silt(i)>=0.8 & clay(i)<0.12
SC{i,:}='SILT';
elseif clay(i)>=0.2 & clay(i)<0.35 & silt(i)<0.28 & sand(i)>0.45
SC{i,:}='SANDY CLAY LOAM';
elseif clay(i)>=0.27 & clay(i) <0.4 & sand(i)>0.2 & sand(i)<=0.45
SC{i,:}='CLAY LOAM';
elseif clay(i)>=0.27 & clay(i)<0.4 & sand(i)<=0.2
SC{i,:}='SILTY CLAY LOAM';
elseif clay(i)>=0.35 & sand(i)>=0.45
SC{i,:}='SANDY CLAY';
elseif clay(i)>=0.4 & silt(i)>=0.4
SC{i,:}='SILTY CLAY';
elseif clay(i)>= 0.4 & sand(i)<=0.45 & silt(i)<0.4
SC{i,:}='CLAY';
else
warning('no soil class found')
end
end
%------------------------------------------------------------------------
if varargin{1}==1
close
f1=figure;
%set(gcf,'Color','w','position',[2800 300 600 600])
plot([0 100],[0 0],'k');hold on
set(gca,'XDir','reverse')
plot([0 50],[0 50],'k')
plot([50 100],[50 0],'k')
xlabel('Sand [%]')
text(110,30,'Clay [%]','FontSize',14)
text(15,30,'Silt [%]','FontSize',14)
text(55,-5,'Sand [%]','FontSize',14)
p1=fill([100 90 95 100],[0 0 5 0],'w')
text(97,1.5, 'Sand','color','k')
p2= fill([90 70 92.5 95 90],[0 0 7.5 5 0],'w')
text(87,1.5,{'Loamy';' sand'})
p3=fill([70 50 46.7 55 62 90 92.4 70],[0 0 3.5 3.5 10 10 7.5 0],'w')
text(75,5,'Sandy Loam')
p4=fill([55 46.7 38 58.1 62 55],[3.5 3.5 13.5 13.5 10 3.5],'w')
text(55,7.5,'Loam')
p5=fill([50 20 13.5 6 13.2 38 50],[0 0 6 6 13.5 13.5 0],'w')
text(35, 5, 'Silt Loam')
p6=fill([20 0 6 13.5 20],[0 0 6 6 0],'w')
text(12,2.5,'Silt')
p7=fill([90 62 58.1 62.5 82.5 90],[10 10 13.5 17.5 17.5 10],'w')
text(85,13.5,'Sandy Clay Loam')
p8=fill([58.1 33 40 65 58],[13.5 13.5 20 20 13.5],'w')
text(55,17,'Clay Loam','Color','k')
p9=fill([33 13.5 20 40 33],[13.5 13.5 20 20 13.5],'w')
text(33,16.5,{'Silty';'Clay Loam'})
p10=fill([82.5 62.5 72.5 82.5],[17.5 17.5 27.5 17.5],'w')
text(80,19,'Sandy Clay','Color','k')
p11=fill([65 40 30 50 72.5 65],[20 20 30 50 27.5 20],'w')
text(55,30,'Clay')
p12=fill([40 20 30 40],[20 20 30 20],'w')
text(35,22.5,'Silty Clay','Color','k')
axis square
axis off
i=1;
for i=1:length(sand)
o=100-(1-clay(i))*100; %offset
plot(sand(i)*100+o/2,clay(i)*100,'ok','MarkerFaceColor','k')
end
end
%%get SCINT
SCINT = nan(size(SC,1),1);
SCINT(strcmp(SC,'SAND')) = 1;
SCINT(strcmp(SC,'LOAMY SAND')) = 2;
SCINT(strcmp(SC,'SANDY LOAM')) = 3;
SCINT(strcmp(SC,'LOAM')) = 4;
SCINT(strcmp(SC,'SILT LOAM')) = 5;
SCINT(strcmp(SC,'SILT')) = 6;
SCINT(strcmp(SC,'SANDY CLAY LOAM')) = 7;
SCINT(strcmp(SC,'CLAY LOAM')) = 8;
SCINT(strcmp(SC,'SILTY CLAY LOAM')) = 9;
SCINT(strcmp(SC,'SANDY CLAY')) = 10;
SCINT(strcmp(SC,'SILTY CLAY')) = 11;
SCINT(strcmp(SC,'CLAY')) = 12;
%%get SC2:
SC2 = SC;
SC2 = strrep(SC2,'SAND','S');
SC2 = strrep(SC2,'LOAMY SAND','LS');
SC2 = strrep(SC2,'SANDY LOAM','SL');
SC2 = strrep(SC2,'LOAM','L');
SC2 = strrep(SC2,'SILT LOAM','SIL');
SC2 = strrep(SC2,'SILT','SI');
SC2 = strrep(SC2,'SANDY CLAY LOAM','SCL');
SC2 = strrep(SC2,'CLAY LOAM','CL');
SC2 = strrep(SC2,'SILTY CLAY LOAM','SICL');
SC2 = strrep(SC2,'SANDY CLAY','SC');
SC2 = strrep(SC2,'SILTY CLAY','SIC');
SC2 = strrep(SC2,'CLAY','C');
SC2 = strrep(SC2,' ','');
SC2 = strrep(SC2,'Y','');
%test: [SC,~,~,SC2] = soil_classification([0:0.1:1,0:0.1:0.5],[1:-0.1:0,0:0.1:0.5],'usda',0)
end %of function
To produce the figure, put the following into the command window:
soil_classification([0.6,0.2,.3,.4,.3,.1,.1,.8,.6,.9,.73,.6,.55,.64,.69,.1], [0.3,0.6,.3,.2,.1,.5,.3,.1,.1,.1,.1,.34,.11,.27,.13,.5], 'usda',1)
Thanks!

Respuestas (1)

Rik
Rik el 28 de Nov. de 2017
Editada: Rik el 28 de Nov. de 2017
Make sure daspect is set to [1 1 1].
You can also use the FEX submission I wrote when you asked about a grid.

Categorías

Más información sobre Agriculture en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by