Conversion of (129x7 complex double) to an Image
19 views (last 30 days)
Show older comments
Muhammad on 4 Feb 2023
Commented: DGM on 7 Feb 2023
I have a variable s (129x7 complex double). I want to save it as an image. I have tried many ways but I can't save it.
s = spectrogram(cm(:,k));
save(['Spectro_Subj' num2str(h) '_channel' num2str(i) '_window' num2str(k) '.mat'],'s')
Tiff supports ComplexIEEEFP. However MATLAB's interface to libTiff does not support that.
Image Analyst on 6 Feb 2023
Edited: Image Analyst on 7 Feb 2023
baseFileName = sprintf('Spectro_Subject %d_channel %d_window %d.png', h, i, k);
fullFileName = fullfile(pwd, baseFileName);
fprintf('For k = %d, saving "%s".\n', k, fullFileName);
DGM on 7 Feb 2023
Note the only reason why I don't use exportgraphics() isn't because saveas() is better. I just run an older version, so I can't verify my example with something I can't run.
More Answers (2)
you could use the tiff gateway and write the imaginary component as unassociated alpha. There is an example at
The difference is that you would specify 2 samples per pixel instead of 4, and you would use IEEEFP sample format.
There is a file exchange contribution for writing floating-point tiff that is worth studying.
So... you would be able to use an image file, and use floating point samples, and write two channels.
What you should not expect is for any other program to be able to produce a readable image from the data
DGM on 4 Feb 2023
Moved: Image Analyst on 6 Feb 2023
Are you sure you don't want to just save a graphical representation (i.e. a plot)?
% some fake test signal
fs = 1000;
t = 0:1/fs:2-1/fs;
y = chirp(t,100,1,200,'quadratic');
% plot the spectrogram
% save the figure
If so, there are many different ways it can be represented.
Find more on Convert Image Type 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!