Borrar filtros
Borrar filtros

How to check if custom terrain object with a given name already exists?

5 visualizaciones (últimos 30 días)
Mike Fox
Mike Fox el 14 de Jul. de 2023
Respondida: Sathvik el 25 de Jul. de 2023
I am using the function addCustomTerrain in a script to create a custom terrain object.
addCustomTerrain("terrainname",myfile,"Attribution",attribution,"WriteLocation",writelocation)
When running the code, if the custom terrain object already exists MATLAB will give an error:
Error using addCustomTerrain
Terrain 'terrainname' already exists.
I would like to write the script such that if the terrain already exists it will skip adding the terrain (so I can just run the program all the way through). Is there a way to check if the custom terrain object already exists or otherwise handle this error without stopping the program?

Respuestas (1)

Sathvik
Sathvik el 25 de Jul. de 2023
Hi Mike
I understand that you want to write a script that skips adding the terrain if the terrain exists. You can use a try catch block to implement this:
try
addCustomTerrain("terrainname",myfile,"Attribution",attribution,"WriteLocation",writelocation)
catch ME
if strcmp(ME.identifier, 'shared_terrain:terrain:TerrainNameExists')
%Do nothing
else
rethrow(ME);
end
end
Here's a link to the documentation for the 'try catch' block.
Hope this helps!

Etiquetas

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by