matlab - Error: Output argument "Clus_Area" (and maybe others) not assigned during call to -
have 2 matrices, dimensions 1440 rows 241 columns. first matrix populates each cell area, , second contains values 0 871. these cells grouped, , values 1 871 represent different groups, ie group 1 comprised of 10 neighboring cells, group 2 comprised of 20 neighboring cells, etc.
i want build third matrix, 871 rows 1 column, lists area of each group of cells second matrix, areas calculated summing relevant cells first matrix.
i tried running function, keep getting error:
clear clear load clusters_28aug.mat; ar = a>0; u = cluster_area(ar)
error in cluster_area (line 13) = 1; output argument "clus_area" (and maybe others) not assigned during call to.
i thought variable assigned within function. how can fix this?
here code:
function clus_area = cluster_area(ar) % summer 2013 project % % purpose: determine area of each cluster, adding individual areas of each cell within cluster. % input % ar(i,j) = clusters id'd, on 1440 x 241 matrix % % output % clus_area(i,j) = area of each cluster, single column vector, indexed cluster # = 1; j = 1; = 1:1440; %for longitudes j = 1:120; %for 30s equator, convert 0.25 deg lon km, varies latitude if ar > 0; b_1 = (111.41288*cosd(abs((0.25*(j+239))-90)))-(0.0935*cosd(abs(3*((0.25*(j+239))-90))))+(0.00012*cosd(abs(5*((0.25*(j+239))-90)))); b_2 = (111.41288*cosd(abs((0.25*(j+240))-90)))-(0.0935*cosd(abs(3*((0.25*(j+240))-90))))+(0.00012*cosd(abs(5*((0.25*(j+240))-90)))); %use area formula trapezoid = 1/2 h (b_1+b_2), h = 27.8km area_cell = (((0.5)*27.8*1000)*((b_1+b_2)*1000)); %ans converted m^2 %add cell areas cluster area clus_area(i,j) = sum(area_cell); disp('clus_area') %populate grid_lat_lon area of each cell %grid_lat_lon(i,j) = area_cell; end end j = 121:241; %for equator 30n, convert 0.25 deg lon km, varies latitude if ar > 0; b_1 = (111.41288*cosd(((0.25*(j+239))-90)))-(0.0935*cosd((3*((0.25*(j+239))-90))))+(0.00012*cosd((5*((0.25*(j+239))-90)))); b_2 = (111.41288*cosd(((0.25*(j+240))-90)))-(0.0935*cosd((3*((0.25*(j+240))-90))))+(0.00012*cosd((5*((0.25*(j+240))-90)))); %use area formula trapezoid = 1/2 h (b_1+b_2), h = 27.8km area_cell = (((0.5)*27.8*1000)*((b_1+b_2)*1000)); %ans converted m^2 %add cell areas cluster area clus_area(i,j) = sum(area_cell); disp('clus_area') %populate grid_lat_lon area of each cell %grid_lat_lon(i,j) = area_cell; end end end z = clus_area(i,j); end
don't mean say
if ar(i,j)>0
i'm not sure semantics of if statement when expression results in array, think might require elements of expression true.
Comments
Post a Comment