Unable to display variable as image
1 view (last 30 days)
Show older comments
I have the folowing variable
submat =
7×13 single matrix
16.1094 16.3903 12.4469 33.8613 6.7100 20.3669 27.7830 23.1273 10.9647 15.3839 43.2814 25.0800 4.9771
26.0134 21.7846 24.5541 10.7064 24.3345 8.5626 38.1821 13.5120 12.4108 12.7480 14.2511 11.5835 10.3106
21.8898 26.0016 24.3997 36.9177 14.0322 12.7298 11.1593 16.2164 8.3326 3.4838 23.6294 16.0808 8.5209
21.7488 11.4966 17.9432 14.3220 13.1865 25.7872 53.9011 3.9896 3.8928 5.3149 9.3588 3.3960 12.8622
23.8734 52.9111 25.0016 13.5389 9.8117 17.7362 3.2283 32.2506 25.0688 14.9008 15.3365 5.6434 12.1325
34.5103 37.3330 13.4962 22.7538 6.1432 26.1014 14.8352 3.0524 10.7713 7.0607 13.4558 12.8980 11.2999
8.4102 26.0903 13.1611 23.0215 21.3333 31.7792 19.9027 30.4275 15.3688 27.6668 17.8407 17.7286 19.2649
I want to display it as an image. The "figure" window opens, but it does not contain anything.

I have tried with imshow, image, imagesc, the result is always the same. What could be the problem?
0 Comments
Answers (3)
VBBV
on 4 Jan 2023
D = [16.1094 16.3903 12.4469 33.8613 6.7100 20.3669 27.7830 23.1273 10.9647 15.3839 43.2814 25.0800 4.9771
26.0134 21.7846 24.5541 10.7064 24.3345 8.5626 38.1821 13.5120 12.4108 12.7480 14.2511 11.5835 10.3106
21.8898 26.0016 24.3997 36.9177 14.0322 12.7298 11.1593 16.2164 8.3326 3.4838 23.6294 16.0808 8.5209
21.7488 11.4966 17.9432 14.3220 13.1865 25.7872 53.9011 3.9896 3.8928 5.3149 9.3588 3.3960 12.8622
23.8734 52.9111 25.0016 13.5389 9.8117 17.7362 3.2283 32.2506 25.0688 14.9008 15.3365 5.6434 12.1325
34.5103 37.3330 13.4962 22.7538 6.1432 26.1014 14.8352 3.0524 10.7713 7.0607 13.4558 12.8980 11.2999
8.4102 26.0903 13.1611 23.0215 21.3333 31.7792 19.9027 30.4275 15.3688 27.6668 17.8407 17.7286 19.2649]
imshow(D) % this does not work
imagesc(D) % this works
3 Comments
Image Analyst
on 4 Jan 2023
@VBBV "imshow takes only filenames as inputs" is not true. imshow takes image variables as inputs as well as filenames. Perhaps you were thinking of imread which takes only filenames.
Image Analyst
on 4 Jan 2023
Because your submat is floating point, and not within the range 0 to 1, you'll need to use [] when you call imshow(). If you don't do that than any values more than 1 will be considered as being 1 (clipped to white) and any values less than 0 will be considered as 0 (clipped to black). Because all of your values were more than 1, the image showed up as all white.
Try this, using [] in imshow:
submat = [16.1094 16.3903 12.4469 33.8613 6.7100 20.3669 27.7830 23.1273 10.9647 15.3839 43.2814 25.0800 4.9771
26.0134 21.7846 24.5541 10.7064 24.3345 8.5626 38.1821 13.5120 12.4108 12.7480 14.2511 11.5835 10.3106
21.8898 26.0016 24.3997 36.9177 14.0322 12.7298 11.1593 16.2164 8.3326 3.4838 23.6294 16.0808 8.5209
21.7488 11.4966 17.9432 14.3220 13.1865 25.7872 53.9011 3.9896 3.8928 5.3149 9.3588 3.3960 12.8622
23.8734 52.9111 25.0016 13.5389 9.8117 17.7362 3.2283 32.2506 25.0688 14.9008 15.3365 5.6434 12.1325
34.5103 37.3330 13.4962 22.7538 6.1432 26.1014 14.8352 3.0524 10.7713 7.0607 13.4558 12.8980 11.2999
8.4102 26.0903 13.1611 23.0215 21.3333 31.7792 19.9027 30.4275 15.3688 27.6668 17.8407 17.7286 19.2649];
imshow(submat, []) % This does work if you use [] to autoscale the data.
imagesc(submat) % this also works but applies some default colormap that you probably don't want.
If you use imshow(), you can then pseudocolor the image with a colormap with the colormap() function if you want, otherwise it shows up as grayscale.
0 Comments
See Also
Categories
Find more on Printing and Saving in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!