Subscript indices error, excel, textscan.
Afficher commentaires plus anciens
Matlab is giving me:
"Subscript indices must either be real positive integers or logicals.
Error in testt (line 40)
if idx(x) < idx1(j) && idx(x+1) > idx1(j)"
I already tried to use the function "round" and i dont had success. My program analyze a .txt file (i have upload the file "items.txt") and select specific words like, "bonus_damage", "ItemCost" and "bonus_amor". Than it organize all this data using the position of each data ("idx", "idx1" and "idx2"). The variables "iwant", "iwant1" and "iwant2" gives me the numbers that i want to write into a excel spreadsheet. The if statements like if "idx(x) < idx1(j) && idx(x+1) > idx1(j)" gives the exact location of where i need to write each data.
Thanks
function x=testt()
fid = fopen('items.txt') ;
S = textscan(fid,'%s','delimiter','\n') ;
S = S{1} ;
idx = strfind(S, '"ItemCost"');
idx = find(not(cellfun('isempty',idx)));
ACD = S(idx) ;
b=regexp(ACD,'\d+(\.)?(\d+)?','match') ;
iwant=str2double([b{:}]);
y=size(iwant);
tit{1}='ItemCost';
my_cell = sprintf( 'B%s',num2str(1) );
xlswrite('testitens3.xlsx',tit,'Sheet1',my_cell);
idx1 = strfind(S, '"bonus_damage"');
idx1 = find(not(cellfun('isempty',idx1)));
ACD1 = S(idx1) ;
b1=regexp(ACD1,'\d+(\.)?(\d+)?','match') ;
iwant1=str2double([b1{:}]);
for k=1:y(2)
my_cell = sprintf( 'B%s',num2str(k+1) );
xlswrite('testitens3.xlsx',iwant(k),'Sheet1',my_cell);
end
tit{1}='bonus_damage';
my_cell = sprintf( 'C%s',num2str(1) );
xlswrite('testitens3.xlsx',tit,'Sheet1',my_cell);
j=1;
x=0;
while j<1000
if idx(x) < idx1(j) && idx(x+1) > idx1(j)
my_cell = sprintf( 'C%s',num2str(x+1) );
xlswrite('testitens3.xlsx',iwant1(j),'Sheet1',my_cell);
j=j+1;
end
x=x+1;
if x==y(2)
j=1001;
end
end
idx2 = strfind(S, '"bonus_armor"');
idx2 = find(not(cellfun('isempty',idx2)));
ACD2 = S(idx2) ;
b2=regexp(ACD2,'\d+(\.)?(\d+)?','match') ;
iwant2=str2double([b2{:}]);
idx2=round(idx2);
iwant2=round(iwant2);
tit{1}='bonus_armor';
my_cell = sprintf( 'D%s',num2str(1) );
xlswrite('testitens3.xlsx',tit,'Sheet1',my_cell);
j=1;
x=0;
while j<1000
if idx(x) < idx2(j) && idx(x+1) > idx2(j)
my_cell = sprintf( 'D%s',num2str(x+1) );
xlswrite('testitens3.xlsx',iwant2(j),'Sheet1',my_cell);
j=j+1;
end
x=x+1;
if x==y(2)
j=1001;
end
end
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Performance dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!