issue in spectralMatch or am I doing something wrong?

22 views (last 30 days)
Molly Fort
Molly Fort on 28 Oct 2025 at 14:14
Answered: Parth Parikh on 5 Nov 2025 at 5:49
on the page for use of spectralMatch function this code is suggested:
score = spectralMatch(libData,hcube);
bw = score < threshold;
datacube = gether(hcube);
T = reshape(datacube,[size(datacube,1)*size(datacube,2) size(datacube,3)]);
Ts = zeros(size(T));
Ts(bw == 1,:) = T( bw==1 ,:);
Ts = reshape(Ts,[size(datacube,1) size(datacube,2) size(datacube,3)]);
but when run, error code pops up;
Unable to perform assignment because value of type 'hypercube' is not convertible to 'double'.
Caused by:
Error using double
Conversion to double from hypercube is not possible.

Answers (2)

Anmol
Anmol on 3 Nov 2025 at 7:47
Hi Molly,
I understand that you are trying to run the example provided in https://www.mathworks.com/help/releases/R2025b/images/ref/spectralmatch.html for “spectralMatch” function on MATLAB R2024b and while running the code script you are getting this error.
For possible workarounds,
  1. You can try running this example https://www.mathworks.com/help/releases/R2024b/images/ref/spectralmatch.html based on the version of MATLAB you are using.
  2. You can also try using “hcube.DataCube” instead of datacube = gather(hcube) in the code, as it might be possible the conversion is happening incorrectly.
I hope you find this useful.

Parth Parikh
Parth Parikh 6 minutes ago
Hi Molly,
Thank you for bringing this issue. I’ve tested the spectralMatch example, and it appears to be running correctly on my end. To assist you further, could you please provide more details about how your hcube object was created? Additionally, which version of MATLAB are you currently using? Assuming that gether(hcube) is a typo. These information will help me give you a more precise answer.
Just to note that if you are using gather(hcube) in MATLAB versions R2024b or earlier, you might encounter issues because data retrieval was handled via hcube.DataCube in those versions.

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!