Using sprintf function?
7 views (last 30 days)
Show older comments
Hi All,
I have Excel file which has names of outputs. I want to save the output images as the same names in the excel file.
Thank you in advance
Here is my code
clear all, clc
cd C:\Calculated_NDVI_Arcgis
dinfo = dir('*_B3*.tif');
nfile = length(dinfo);
filenames = {dinfo.name};
for K = 1 : nfile
b3_file{K} = filenames{K};
band_pos{K} = strfind(b3_file{K}, '_B3');
b4_file{K} = b3_file{K}; b4_file{K}(band_pos{K} + 2) = '4';
b3_data{K} = double( imread(b3_file{K}) );
b4_data{K} = double( imread(b4_file{K}) );
finalndvi{K} = (b4_data{K} - b3_data{K}) ./ (b4_data{K} + b3_data{K});
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
finalndvi{K}=flipud(finalndvi{K});
R = georasterref('RasterSize',size(finalndvi{K}),'LatitudeLimits',[30.95115,31.76385],'LongitudeLimits',[46.58315,47.43285]);
[num,txt] = xlsread('NDVI_data_name.xls','Sheet1','A1:A2');
geotiffwrite(sprintf(txt.tif,K),finalndvi{K},R);
end
2 Comments
Answers (1)
Dan Klemfuss
on 24 Jan 2018
Good evening Reyadh. I believe the issue that you're having with sprintf is that it needs to be formatted as a string. You currently have:
geotiffwrite(sprintf(txt.tif,K),finalndvi{K},R);
I believe that it needs to be modified to:
geotiffwrite(sprintf('%s.tif',txt),finalndvi{K},R);
This will assign the value of txt where the %s is. Please let me know if you have any questions!
6 Comments
See Also
Categories
Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!