wschwanghart / topotoolbox

A MATLAB software for the analysis of digital elevation models -
https://topotoolbox.wordpress.com/
153 stars 89 forks source link

Error in computing river bedslope #42

Closed carlderas closed 1 month ago

carlderas commented 5 months ago

Hello! I am a geologist researcher, who uses the Topotoolbox to automatically delineate and compute river bedslope via knickpoints using data from IfSAR. I have been using the code for a long time, and this the first time I'd encountered such issue when I try computing for river bedslope using the Topotoolbox code.

To compute for river bedslope, first, we sort the attribute data using these codes: shapefile='C:\Users\USER\Documents\MATLAB\TopoToolbox\knickpoints_filename.shp'; S = shaperead(shapefile);
attributeData = [S.distup]; [sortedData, sortedIndices] = sort(attributeData); sortedShapefile = S(sortedIndices); shapewrite(sortedShapefile,'C:\Users\USER\Documents\MATLAB\TopoToolbox\sorted_data_filename.shp');

Then, the difference in slope and elevation values are computed using these codes: shapefile = 'C:\Users\USER\Documents\MATLAB\TopoToolbox\sorted_data_filename.shp'; S = shaperead(shapefile); shapefileTable = struct2table(S); attributeData_dist = shapefileTable.distup; diff_dist = diff(attributeData_dist); shapefileTable.diff_dist = [NaN; diff_dist]; attributeData_elev = shapefileTable.elev; diff_elev = diff(attributeData_elev); shapefileTable.diff_elev = [NaN; diff_elev];

River bedslope is computed via these next series of codes: attributeData1 = shapefileTable.diff_elev; attributeData2 = shapefileTable.diff_dist; riverbedslope = attributeData1 ./ attributeData2;
shapefileTable.riverbedslope = riverbedslope; updatedShapefile = table2struct (shapefileTable); shapewrite(updatedShapefile,'C:\Users\USER\Documents\MATLAB\TopoToolbox\riverbedslope_filename.shp');

Now, when I'm on the part of constructing a table using updatedShapefile = table2struct at the part of computing for river bedslope, I encounter this error: Not enough input arguments.

Error in table2struct (line 31) s = cell2struct(table2cell(t),matlab.internal.tabular.makeValidVariableNames(t.Properties.VariableNames,'warn'),2);

Any ideas on how to resolve this error, or why this happens is very much appreciated. Thank you so much.

wschwanghart commented 2 months ago

Dear @carlderas hm, that's a difficult one as you are using your own shapefiles. I have no ideas where the problem comes from. Did you check the function table2STREAMobj? Cheers, Wolfgang