Help with the code for converting hyperspectral image to excel file

3 views (last 30 days)
please check and let me know how to run this code on matlab. I already used hypertools for clustering and now need help with the code given below.
cellsample=who('prep_sample');
cellmask=who('prep_mask');
cellsizeofsample= size(cellsample);
width = cellsizeofsample(1,1);
column=cellsizeofsample(1,2);
cellmaskedsampleimage = cell(width,column);
for i=1:width
mask=eval(cellmask{i,1});
sample=eval(cellsample{i,1});
cellmaskedsampleimage{i,1} = maskedimg(mask,sample);
end
clear mask sample 1
cellarrayconerted2matrix= cell(width,column);
for i=1:width
sample=cellmaskedsampleimage(i,1);
band=size(sample);
band=band(i,3);
cellarrayconerted2matrix(i,1)=reshape(sample,[],band);
end
clear sample Band 1
cellfinaldata = cell(width,column);
for i = 1:width
data = cellarrayconvertedtomatrix(i,1);
data( ~any(data,2), : ) = [];
cellfinaldata(i,1)=data;
end
clear data 1
mkdir Output;
dataSaveDir = 'Output'
dataname = 'Soybean_'
datasetname='X';
fileextension = '_txt.';
for i=1:width
filename=[dataSaveDir,dataname, datasetname,num2str(i),fileextension];
writematrix(cellfinaldata(i,1), filename);
end
for i=1:width
filename=[dataSaveDir, dataname,datasetname,num2str(i),'.csv'];
writematrix(cellfinaldata(i,1), filename);
end
clear filename : column width cellsizeofsample
MatfileName = ('workspace');
filename= [dataSaveDir, dataname, datasetname, MatfileName, 'mat'];
save(filename);
clear dataSaveDir dataname datasetname fileextension Matfilename filename

Answers (1)

Image Analyst
Image Analyst on 24 Jun 2022
Try this:
baseFileName = sprintf('%s%s%d.xlsx', dataname, datasetname, i);
fullFileName = fullfile(dataSaveDir, baseFileName);
writematrix(cellfinaldata(i,1), fullFileName);
  8 Comments
Walter Roberson
Walter Roberson on 24 Jun 2022
You have two calls
writematrix(cellfinaldata(i,1), filename);
Change each of those to
writematrix(cellfinaldata{i,1}, filename);

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!