MATLAB scares me - Programmers Heaven

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

#### Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

# MATLAB scares me

Posts: 1Member
Hi Guys,

I've got a bit of a problem in MATLAB.
I'll try to explain this as best I can but if you have any queries then please ask.

So... I've downloaded some information from the Hi-Flows/FEH website (all about rivers and flooding) and I've used MATLAB in conjunction with this information to put it into a more readable format in Excel.
I want to find values for Q (flow) but I cannot find an equation for it. I have been told that the values for Q are a part of the information downloaded from the FEH website but are not coming out in the excel file because it hasn't been put into MATLAB. I tried to do it but I'm assuming I need to use the correct 'name' for Q for it to come out but I don't know it.
Below is the MATLAB file I'm using:
% and calculates the QMED from the .AM files

clear;

fprintf('Running FEH data file convertor...
');

% Select FEH file types to read (1 to select, 0 to omit):
% CD2
CD=1;
% AM
AM=1;
% PT - not implemented in this script
PT=0;

% Name of output file
FEH_output_name = 'FEH data';

% Starting station number (lower)
gauge_start_num = 43001;

% End station number (upper)
gauge_end_num = 53028;

num_gauges = gauge_end_num - gauge_start_num + 1;

FEH_output_file = strcat(FEH_output_name,'.xls');
fid_out = fopen(FEH_output_file,'w');
fprintf(fid_out,'Station Catchment Gauge Nominal Area Nominal NGR DTM NGR DTM Area ALTBAR ');
fprintf(fid_out,'ASPBAR ASPVAR BFIHOST DPLBAR DPSBAR FARL LDP PROPWET RMED-1H RMED-1D RMED-2D ');
fprintf(fid_out,'SAAR SAAR4170 SPRHOST URBCONC1990 URBEXT1990 URBLOC1990 URBCONC2000 URBEXT2000 ');
fprintf(fid_out,'URBLOC2000n Suitable for QMED Suitable for Pooling ');
fprintf(fid_out,'Station Description Catchment Description QMED Record Length');
for i = 1:num_gauges
station = gauge_start_num + i - 1;
if CD == 1
file_name = int2str(station);
CD_filename = strcat(file_name, '.CD2');
% Read FEH .CD2 text file
if exist(CD_filename)==2
fprintf('%s
',CD_filename);
fid_in = fopen(CD_filename);
for j = 1:5
dump_text = fgets(fid_in);
end
stn = str2num(fgets(fid_in));
fprintf(fid_out,'
%d ',stn);
dump_text = fgets(fid_in);
dump_text = fgets(fid_in);
status = fseek(fid_in,5,'cof');
catchment = fgetl(fid_in);
fprintf(fid_out,'%s ',catchment);
status = fseek(fid_in,9,'cof');
location = fgetl(fid_in);
fprintf(fid_out,'%s ',location);
status = fseek(fid_in,13,'cof');
nom_area = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',nom_area);
status = fseek(fid_in,12,'cof');
nom_ngr = fgetl(fid_in);
fprintf(fid_out,'%s ',nom_ngr);
dump_text = fgets(fid_in);
dump_text = fgets(fid_in);
status = fseek(fid_in,13,'cof');
ihdtm_ngr = fgetl(fid_in);
fprintf(fid_out,'%s ',ihdtm_ngr);
status = fseek(fid_in,9,'cof');
dtm_area = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',dtm_area);
status = fseek(fid_in,7,'cof');
alt_bar = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',alt_bar);
status = fseek(fid_in,7,'cof');
asp_bar = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',asp_bar);
status = fseek(fid_in,7,'cof');
asp_var = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',asp_var);
status = fseek(fid_in,8,'cof');
bfi_host = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',bfi_host);
status = fseek(fid_in,7,'cof');
dpl_bar = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',dpl_bar);
status = fseek(fid_in,7,'cof');
dps_bar = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',dps_bar);
status = fseek(fid_in,5,'cof');
farl = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',farl);
status = fseek(fid_in,4,'cof');
ldp = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',ldp);
status = fseek(fid_in,8,'cof');
prop_wet = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',prop_wet);
status = fseek(fid_in,8,'cof');
rmed_1h = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',rmed_1h);
status = fseek(fid_in,8,'cof');
rmed_1d = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',rmed_1d);
status = fseek(fid_in,8,'cof');
rmed_2d = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',rmed_2d);
status = fseek(fid_in,5,'cof');
saar = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',saar);
status = fseek(fid_in,9,'cof');
saar_4170 = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',saar_4170);
status = fseek(fid_in,8,'cof');
spr_host = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',spr_host);
status = fseek(fid_in,12,'cof');
urb_conc_1990 = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',urb_conc_1990);
status = fseek(fid_in,11,'cof');
urb_ext_1990 = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',urb_ext_1990);
status = fseek(fid_in,11,'cof');
urb_loc_1990 = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',urb_loc_1990);
status = fseek(fid_in,12,'cof');
urb_conc_2000 = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',urb_conc_2000);
status = fseek(fid_in,11,'cof');
urb_ext_2000 = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',urb_ext_2000);
status = fseek(fid_in,11,'cof');
urb_loc_2000 = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',urb_loc_2000);
dump_text = fgets(fid_in);
dump_text = fgets(fid_in);
status = fseek(fid_in,5,'cof');
QMED_yes = fgetl(fid_in);
fprintf(fid_out,'%s ',QMED_yes);
status = fseek(fid_in,8,'cof');
POOLING_yes = fgetl(fid_in);
fprintf(fid_out,'%s ',POOLING_yes);
dump_text = fgets(fid_in);
dump_text = fgets(fid_in);
status = fseek(fid_in,8,'cof');
stn_desc = fgetl(fid_in);
fprintf(fid_out,'%s ',stn_desc);
status = fseek(fid_in,10,'cof');
catch_desc = fgetl(fid_in);
fprintf(fid_out,'%s',catch_desc);
status = fclose(fid_in);
end
end
if AM == 1
AM_filename = strcat(file_name, '.AM');
% Read FEH .AM text file
if exist(AM_filename)==2
fprintf('%s
',AM_filename);
fid_in1 = fopen(AM_filename);
m = 0;
% Check for start and end records of AMS in AM file
while feof(fid_in1) == 0
m = m + 1;
upperlim = m;
end
lowerlim = m;
end
status = fclose(fid_in1);
fid_in2 = fopen(AM_filename);
for j = 1:upperlim
dump_text = fgets(fid_in2);
end
num_ams = 1;
for n = (upperlim+1):(lowerlim-1)
ams_data(num_ams) = textscan(fid_in2, '%*s %*s %*s %9.3f %*s %*s', 1);
num_ams = num_ams + 1;
end
rec_length = num_ams - 1;
% Convert cell array to numeric array
for p = 1:rec_length
ams_values(p) = ams_data{p};
end
% Read no. of AMS values to match record length
% and avoid re-using AMS values from previous
% station when calculating median
ams = ams_values(1:rec_length);
status = fclose(fid_in2);
% Calculate QMED
qmed = median(ams);
fprintf(fid_out,' %12.5f ',qmed);
fprintf(fid_out,'%d',rec_length);
end
end
if PT == 1
% Read FEH .PT text file - not implemented yet
PT_filename = strcat(file_name, '.PT');
end
end

status = fclose(fid_out);

fprintf('run completed
');

Any help would be greatly appreciated.
Thanks