My excel file is been created as shown at "result.jpg".
I want something as shown at "WhatIWant.jpg"
The txt file is uploaded as "items.txt"
Thanks.
function x=testt()
fid = fopen('items.txt','r');
k=1;
while 1
tline = fgetl(fid);
if strfind(tline, 'AbilityCooldown')>0
x=strfind(tline, 'AbilityCooldown')
% tline(x:end)
sprintf('%s %f',tline)
my_cell = sprintf( 'A%s',num2str(k) );
xlswrite('testitens2.xlsx',tline,'Sheet1',my_cell);
k=k+1;
end
if ~ischar(tline)
break
end
end
end

 Réponse acceptée

KSSV
KSSV le 13 Déc 2016

0 votes

fid = fopen('items.txt') ;
S = textscan(fid,'%s','delimiter','\n') ;
S = S{1} ;
idx = strfind(S, 'AbilityCooldown');
idx = find(not(cellfun('isempty',idx)));
%
ACD = S(idx) ;
b=regexp(ACD,'\d+(\.)?(\d+)?','match') ;
iwant=str2double([b{:}])
You have the AbilityCooldown numbers in array, you can write into excel at a stretch.

Plus de réponses (1)

Lucas Santana
Lucas Santana le 13 Déc 2016

0 votes

Thanks a lot! My program works fine but im having trouble on fully understanding what this code do. Could you explain for me?
idx = strfind(S, 'AbilityCooldown');
idx = find(not(cellfun('isempty',idx)));
%
ACD = S(idx) ;
b=regexp(ACD,'\d+(\.)?(\d+)?','match') ;
iwant=str2double([b{:}])
Here is my final program.
function x=testt()
fid = fopen('items.txt') ;
S = textscan(fid,'%s','delimiter','\n') ;
S = S{1} ;
idx = strfind(S, 'AbilityCooldown');
idx = find(not(cellfun('isempty',idx)));
%
ACD = S(idx) ;
b=regexp(ACD,'\d+(\.)?(\d+)?','match') ;
iwant=str2double([b{:}])
y=size(iwant)
tit{1}='AbilityCooldown';
my_cell = sprintf( 'B%s',num2str(1) );
xlswrite('testitens2.xlsx',tit,'Sheet1',my_cell);
for k=1:y(2)
my_cell = sprintf( 'B%s',num2str(k+1) );
xlswrite('testitens2.xlsx',iwant(k),'Sheet1',my_cell);
end
x=0;
end

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by