How can I extract the numerical array from a hypercube object?
Mostrar comentarios más antiguos
Hi! I've been using the hyperspectral library for the image processing toolbox for some years now. In the beggining, when a variable of class hypercube was created, it was storing the nomerical array (i.e. the spectral image) in a struct way that you could acces via dot indexing, for instance:
spectral_image = cube.DataCube;
However this seems not to be working anymore. Instead if I try this, I get a string instead of a numerical array. I've cheked and there is a funcion called gather which is supposed to be for this. I have also tried:
spectral_image = gather(cube);
But it is also not working. I get the following error, but my spectral image fits more than enough in my RAM, so I am sure this is not a problem.
Dot indexing is not supported for variables of this type.
Error in hypercube/gather (line 1398)
if isa(obj.BlockedDataCube.Adapter,'images.blocked.InMemory')
^^^^^^^^^^^^^^^^^^^^^^^^^^^
The problem is that I have spectral images stored in files in hypercube class that I saved some time ago with Matlab R2023 version or even earlier, but now I can not access directly to this numerical arrays that previously were perfectly fitting in my RAM.
Any clue about how could I fix this?
Thanks in advance.
Respuesta aceptada
Más respuestas (1)
Parth Parikh
el 5 de Feb. de 2026 a las 4:17
0 votos
Hi Miguel,
I completely understand the frustration that comes with adapting to changes in well-established workflows. Moving forward, the best solution is to adopt the latest MATLAB functions for hyperspectral data, namely imhypercube and geohypercube. These provide seamless integration with current features, improved compatibility, and enhanced data management, positioning your work for future updates and optimizations from MATLAB. The helper function is meant to recover data from legacy hypercube objects created before R2025a, for robust, long-term workflows it’s highly recommended to transition to these newer functions. This way, you’ll be able to take advantage of MATLAB’s ongoing improvements with greater ease and reliability.
Note: For multispectral data, MATLAB provides the corresponding immuticube and geomulticube functions.
6 comentarios
Miguel Ángel
el 5 de Feb. de 2026 a las 10:48
Parth Parikh
el 5 de Feb. de 2026 a las 13:22
Sure, we will update the documentation.
@Parth Parikh, your response brushes off the real cost imposed on users as inconsequential and immaterial.
Why on earth if this was going to be done was it not in prior release notes as coming and were not efficient tools provided to aid in the transition rather than dumping all the work onto the user unannounced? This is quite rude.
Why, at least, since Mathworks has access to all the internals could not the new methods be able to discern an object of the prior type and directly return the data stored therein rather than the string? Or at least distribute the prior version (perhaps in an aliased form) in parallel so there would be an (at least relatively) painless way to make the transition? As it is now, if one reverts to a prior release to read the data, there isn't a tool to create the new version directly and as @Miguel Ángel noted, the conversion even replacing str2double is nontrivial.
This was just a very bad move on Mathworks' part in the way the transition was rolled out.
@Miguel Ángel - "Now I am searhing for the fastest way to convert dozens of old hcube objects into the new version, and this will take me too much time. .."
Given the lack of coexisting tools in either the prior or present versions (shame on you, Mathworks!), I suspect the best approach will be to write a batch script to run in the prior release that does a search for the saved objects (I'm assuming they're in a .mat file format?) and extracts the data from them and writes to either another .mat or binary file that can then be read in the later release and create the new objects from the raw data. That could be set to be a background or overnight unattended bach job. Painful and shouldn't be necessary to have to go to such extremes, but better than a one-at-a-time approach.
Another idea all within the later release might try would be to write the string data to a file and then read it in and see if the builtin io format conversion routines of the runtime are any faster than the in memory methods. Again, wny they would do this is beyond comprehension from the user's viewpoint, anyway.
Similar idea would be to compare direct sscanf with double().
ADDENDUM
Not having the TB no way to go look at just what the prior code might be, I wonder if it might be possible to move the previous version over to a private directory on the new and give it an aliased name. It may be it's too intertwined with other supporting internals to be possible, but I'd probably give it a look...
Miguel Ángel
el 5 de Feb. de 2026 a las 18:27
Glad to try, anyway...good luck and let us know how it goes.
I still think this is well deserving a strong ping/complaint about unduly burdening the user with extra overhead cost.
ADDENDUM
Last thought...I think I'd request a working version of the old hcube object code that can be run with the new release, or conversely, a method that can use in the prior release to create the new objects as part of that complaint. It's only what they should have done to begin with.
Categorías
Más información sobre Hyperspectral Image Processing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!