creating a string variable to be used in xlswrite

2 次查看(过去 30 天)
Dear all,
I have
[N,T,R]=xlsread(Name);
where
Name={'Input_DE_carrots.xlsx'}
The DE which represents the country changes for every country as well as the name of the product which in the previous example is "carrots"
I want to have
product={'carrots' 'vegetables' 'tomatoes'}
country={'DE' 'FR' 'UK'}
Name={'Input_country(1)_product(1).xlsx'}
[N,T,R]=xlsread(Name);
How can I do that?
thanks

采纳的回答

the cyclist
the cyclist 2012-7-13
Name=['Input_',country{1},'_',product{1},'.xlsx']
Note the use of curly brackets when accessing the cell arrays, in order to get at the contents of the cell, not the cell element itself.

更多回答(2 个)

Sean de Wolski
Sean de Wolski 2012-7-13
product={'carrots' 'vegetables' 'tomatoes'}
country={'DE' 'FR' 'UK'}
for ii = 1:numel(product)
sprintf('%s_%s_%i',product{ii},country{ii},ii)
end
And for more info:
doc sprintf

Nirmal
Nirmal 2012-7-13
product={'carrots' 'vegetables' 'tomatoes'};
country={'DE' 'FR' 'UK'};
Name={sprintf('Input_%s_%s.xls',country{1,1},product{1,1})};

类别

Help CenterFile Exchange 中查找有关 Numeric Types 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by