error help in my code

4 Ansichten (letzte 30 Tage)
Naima Reggad
Naima Reggad am 16 Okt. 2022
Kommentiert: Naima Reggad am 16 Okt. 2022
I keep get this error in my code
error: if isnan(data{s}{x,y,z})

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 16 Okt. 2022
Bearbeitet: Walter Roberson am 16 Okt. 2022
That code is fine under the following conditions:
  • data is a cell array
  • s is a positive integer no greater than the number of entries in data
  • the cell array entry data{s} contains a cell array
  • x, y, and z are positive integer scalars
  • x, y, are no greater than the number of rows and columns of data{s}, and z is no greater than the product of all remaining dimensions of the cell
  • the data retrieved is a datatype that isnan() is defined for.
In particular the code would not be valid for these cases:
  • data{s} retrieves a function handle that is intended to be invoked passing in x, y, z
  • data{s} retrieves a numeric array that is to be indexed at x y z
  1 Kommentar
Naima Reggad
Naima Reggad am 16 Okt. 2022
here is the code, could you check it for me
this function gets ADV data and output some mean flow charactristics
%Note that the code is designed for a specific grid of measurements
%(13*7*3) and should be modified if the measuring grid is different
%input: data: a 1*8 cell with 13*7*3 cells inside each cell. data should be
% filtered for reasonable results
%output: mean flow charactristics
% they can removed or modified
% the structure in which results are saved might be different
function [u, v, w, ubar, vbar, wbar, umag, ubar_reach, umag_reach, umag_scenario,umag_depth,...
ubar_depth, vbar_depth, wbar_depth, h, Q, den, fr] = mean_flow(data)
%loop for 8 scenarios, 13 axes in x-dreiction, 7 in y direction, and 3 over
%the depth
for s =1:8
for x = 1:13
for y = 1:7
for z = 1:3
% if the data is NaN, the corresponding flow parameter is
% also saved as NaN
if isnan(data{s}{x,y,z})
u{s}{x,y,z} = NaN;
v{s}{x,y,z} = NaN;
w{s}{x,y,z} = NaN;
ubar{s}(x,y,z) = NaN;
vbar{s}(x,y,z) = NaN;
wbar{s}(x,y,z) = NaN;
umag{s}(x,y,z) = NaN;
end
u{s}{x,y,z} = data{s}{x,y,z}(:,3); %streamwise velocity time series
v{s}{x,y,z} = data{s}{x,y,z}(:,4); %transverse velocity time series
w{s}{x,y,z} = data{s}{x,y,z}(:,5); %vertical velocity time series
ubar{s}(x,y,z) = nanmean(data{s}{x,y,z}(:,3)); %time-averaged streamwise velocity
vbar{s}(x,y,z) = nanmean(data{s}{x,y,z}(:,4)); %time-averaged transverse velocity
wbar{s}(x,y,z) = nanmean(data{s}{x,y,z}(:,5)); %time-averaged vertical velocity
umag{s}(x,y,z) = sqrt(ubar{s}(x,y,z)^2 + vbar{s}(x,y,z)^2 + wbar{s}(x,y,z)^2); %velocity magnitude
end
%here depth-averaged velocities (averaged over 3 points in z
%direction, i.e., z1, z2, and z3) are calculated
umag_depth{s}(x,y) = nanmean(umag{s}(x,y,1:3));
ubar_depth{s}(x,y) = nanmean(ubar{s}(x,y,1:3));
vbar_depth{s}(x,y) = nanmean(vbar{s}(x,y,1:3));
wbar_depth{s}(x,y) = nanmean(wbar{s}(x,y,1:3));
end
end
end
%here reach-averaged velocities for each scenario and each depth (z) is
%calculated, i.e., all velocities over xy grid is averaged
for s = 1:8
for z = 1:3
ubar_reach{s}(:,:,z) = nanmean(ubar{s}(:,:,z),'all');
umag_reach{s}(:,:,z) = nanmean(umag{s}(:,:,z),'all');
end
end
%reach-averaged for all depths (averaged for z1, z2, and z3)
for s = 1:8
umag_scenario(s) = nanmean(umag_reach{s});
end
%these are only for a specific series of measurements
h = [7.61, 9.65, 9.99, 12.75, 11.50, 14.14, 12.86, 15.11]/100; %average flow depth of each scenario
Q = [60,75,60,75,60,75,60,75]/1000; %discharge of each scenario
den = [0,0,3.4,3.4,5.4,5.4,8.3,8.3]/100; %boulder density of each scenario
fr = umag_scenario./(sqrt(9.81*h));
end

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Fluid Dynamics finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by