Help with the code for converting hyperspectral image to excel file

1 ビュー (過去 30 日間)
Amanda Malik
Amanda Malik 2022 年 6 月 24 日
コメント済み: Walter Roberson 2022 年 6 月 24 日
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

回答 (1 件)

Image Analyst
Image Analyst 2022 年 6 月 24 日
Try this:
baseFileName = sprintf('%s%s%d.xlsx', dataname, datasetname, i);
fullFileName = fullfile(dataSaveDir, baseFileName);
writematrix(cellfinaldata(i,1), fullFileName);
  8 件のコメント
Walter Roberson
Walter Roberson 2022 年 6 月 24 日
You have two calls
writematrix(cellfinaldata(i,1), filename);
Change each of those to
writematrix(cellfinaldata{i,1}, filename);

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by