MATLAB Answers

How to assign inputs in a downloaded function

2 views (last 30 days)
Nadine Doiron
Nadine Doiron on 16 Jan 2020
Edited: per isakson on 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);
salt= data{4};
temp= data{3};
This might seem like a simple question but I am new to this.
Thank you very much!!!


Sign in to comment.

Answers (1)

David Hill
David Hill on 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))
mldepth(ii)=interp1(sigma_t([p1, p2]), Z([p1, p2]), sigma_dT);
end % endif
end % endfor
mld=NaN*ones(1, lt*ln);
mld=reshape(mld, lt, ln);
function x=sw_dens(s,t)%s in ppm, t in C

  1 Comment

Nadine Doiron
Nadine Doiron on 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?

Sign in to comment.

Sign in to answer this question.

Translated by