How to assign inputs in a downloaded function

1 Ansicht (letzte 30 Tage)
Nadine Doiron
Nadine Doiron am 16 Jan. 2020
Bearbeitet: per isakson am 16 Jan. 2020
I am using a function created by someone that helps one determine the mixed layer depth in the ocean. I am having trouble assigning the inputs for the function.
Here is a link to the function download where you can actually see the function.
I have tried to look up how to build functions, but I clearly I am not building my own, I am just using an existing one with my own inputs.
The top line of the function itself looks like this:
function [mld]=ra_mld(salt,temp,Z,dT)
This is what I need to use to assign the inputs Z (depth), temp (temperature), and salt (salinity):
pathname= 'C:\Users\w10027892\Desktop\Research\EN642_ship_CTD_cnv\';
fname= '642_5_03_03.cnv';
totname= [ pathname fname];
fid= fopen(totname,'r');
data = textscan(fid,'%n%n%n%n%n%n%n%n%n%n%n%n%n','headerlines',346);
fclose(fid);
Z=data{1};
salt= data{4};
temp= data{3};
This might seem like a simple question but I am new to this.
Thank you very much!!!

Antworten (1)

David Hill
David Hill am 16 Jan. 2020
If you have built the data correctly, you access the function by:
mld = ra_mld(salt,temp,Z);%dT defaults to 1
Function should return the mld. Did you see the note in the prerequisites? You will need the function sw_dens(). You may need to modify the function to support the sw_dens() function. I found a Sea Water Properties Function but it was not exactly what was mentioned. I extracted the sw_dens() function from it, but the function call has three inputs (s,t,0) get rid of the 0 input.
mldepth=NaN(n5, 1);
for ii=1:n5
s=S(:, ii);
t=T(:, ii);
sst_dT=t(1) - dT;
sigma_t=sw_dens(s, t) - 1000;%here
sigma_dT=sw_dens(s(1), sst_dT) - 1000;%here
pos1=find(sigma_t > sigma_dT);
if ((numel(pos1) > 0) && (pos1(1) > 1))
p2=pos1(1);
p1=p2-1;
mldepth(ii)=interp1(sigma_t([p1, p2]), Z([p1, p2]), sigma_dT);
else
mldepth(ii)=NaN;
end % endif
end % endfor
mld=NaN*ones(1, lt*ln);
mld(oce)=mldepth;
mld=reshape(mld, lt, ln);
function x=sw_dens(s,t)%s in ppm, t in C
a=1002.4+754.8*s+236.3*s.^2;
b=(-0.1338-0.935*s-0.0976*s.^2);
c=(-0.003375+0.00996*s-0.439*s.^2);
d=(0.00000313-0.0000163*s+0.000244*s.^2);
x=a+b.*t+c.*t.^2+d.*t.^3;
end
  1 Kommentar
Nadine Doiron
Nadine Doiron am 16 Jan. 2020
Bearbeitet: per isakson am 16 Jan. 2020
Hi David,
Thank you for your response.
I did see the note about having the sea water package. That is part of a toolbox used for evaluating the thermodynamic properties of pure water and seawater. I have that toolbox installed, so I should just be able to create the proper inputs with my data. Right?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Downloads finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by