필터 지우기
필터 지우기

more efficient way of coding a series of string variables which contain a fix subset of strings

조회 수: 2 (최근 30일)
Dear all,
I have the following list
l1= 'di _Aust.xlsx' ;
l2='di _Bel.xlsx' ;
l3='di_Est.xlsx';
l4 = 'di_Fr.xlsx';
l5 = 'di_Ge.xlsx' ;
l6 = 'di_Gre.xlsx';
l7 = 'di_Ire.xlsx' ;
l8 = 'di_Ita.xlsx' ;
l9 = 'di_Nethe.xlsx';
l10 ='di_Portu.xlsx' ;
l11 ='di_Slova.xlsx' ;
l12= 'di_Sloven.xlsx';
l13= 'di_Spa.xlsx' ;
As you can see in any case the only part that changes is “di”. I was wondering if there is a more efficient way of writing this number of lists
For instance,
Kk={‘di’ ‘rt’ ‘ew’ }
And if I have, for example kk(2), then to get the output
l1= 'rt _Aust.xlsx' ;
l2='rt _Bel.xlsx' ;
l3='rt_Est.xlsx';
and so forth

채택된 답변

Thomas
Thomas 2012년 7월 5일
IS this what you need?
kk={'di' 'rt' 'ew' };
name={'Aust' 'Bel' 'Est' 'Fr'};
for ii=1:length(name)
l=strcat(kk(1),'_',name(ii))
% xlswrite(l , data) % here you have your xlswrite
end

추가 답변 (1개)

Mark Whirdy
Mark Whirdy 2012년 7월 5일
Hi Looks like a case for regexp(), but for a more detailed solution I'll need you to reword your question as its difficult to understand exactly what variables you have and the code-behaviour you need.
  댓글 수: 2
antonet
antonet 2012년 7월 5일
Hi. Thanks for your reply
What I have so far
l1= 'di _Aust.xlsx' ;
l2='di _Bel.xlsx' ;
l3='di_Est.xlsx';
l4 = 'di_Fr.xlsx';
xlswrite(l1 , data)
xlswrite(l2 , data)
xlswrite(l3 , data)
xlswrite(l4 , data)
What changes from this algorithm is the letters before the underscore bar inside the string variables l1 l2 l3; that is “di”. Each time I have to replace “di” with something else taken from a long list
list={‘di’, ‘sdrp’,…)
So I have to replace many times the “di” with something else taken from a long list and this process is boring. A more quick approach would cheer me up!
antonet
antonet 2012년 7월 5일
Am I explicit in the question I am asking?. Please feel free to tell me
thanks

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by