Using sprintf function?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Walter Roberson
am 25 Jan. 2018
"I have Excel file which has names of outputs. I want to save the output images as the same names in the excel file."
How is that intended to work? If the 5th file is EK1903BR_B3Q81.tif then how do you know which name in the xls file to use to write it?
Antworten (1)
Dan Klemfuss
am 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 Kommentare
Jan
am 25 Jan. 2018
@reyadh Albarakat: It is still not clear. What do you expect as output of "sprintf(txt.tif, K)"? The command does not work and therefore the readers cannot guess, what you want it to do. "give names to output images" is not clear also. When "txt" is a cell array, containing the data of the Excel file, what to you expect "txt.tif" to contain? Which name do you want for the created images? "txt1.tif"?
Siehe auch
Kategorien
Mehr zu Spreadsheets finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!