how to save the map information in a structure?
0 comentarios
Respuestas (1)
3 comentarios
Hi @Kuldeep,
In order to achieve the desired output, you need to construct a formatted string that encapsulates various pieces of map information. Here is a breakdown of the code:
Variable Definitions
Start by defining individual variables for each piece of information we want to include in our output. This includes the UTM type, several numerical values, directional information, and the datum.
Using sprintf
The sprintf function is employed to format the string. This function allows us to create a string with specific formatting options. The placeholders within the string (e.g., %s, %.1f, %.15f, %d) are replaced by the corresponding variable values. %s is used for strings,%.1f for floating-point numbers with one decimal place,%.15f for floating-point numbers with fifteen decimal places,%d for integers.
Displaying the Output
Finally, use disp to print the formatted string to the console. This will show the output exactly as specified in the requirement. By executing this code, you will obtain the desired output, formatted precisely as requested.
Here is the refined code below which can be customized based on your later needs.
% Define the map information utm = 'UTM'; value1 = 14186.0; value2 = 10802.5; value3 = 434499.57858948375; value4 = 2004780.07582265; value5 = 10.0; value6 = 10.0; value7 = 43; direction = 'North'; datum = 'World Geodetic System 1984'; units = 'units=Meters';
% Create the formatted output map_info = sprintf('map info = {%s,%.1f,%.1f,%.15f,%.15f,%.1f,%.1f,%d,%s,%s,%s}', ... utm, value1, value2, value3, value4, value5, value6, value7, direction, datum, units);
% Display the output disp(map_info);
Please see attached.
Please let me know if you have any further questions.
- For getting the desired result, you can create a custom function which extracts each property from the class. You can use the sprintf method as mentioned by Umar, but instead of using "Value1", "Value2" etc, use the actual fields, for eg: "map_info.ProjType", "map_info.PixelTiePoints", etc.
- Otherwise the cell array that you have already constructed using "struct2cell", you can just loop over the terms and form a separate array/cell array as you need. If the values are numeric or string, append them in "map_info2"(new array), otherwise use a nested loop/do this recursively.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!