How to speed up this script
1 次查看(过去 30 天)
显示 更早的评论
Hey,
I am reading data from a text file using the following script:
tic
for i = 1:2:length(Data);
Data2(i).H0_SoundSpeed = typecast(uint32(hex2dec(cell2mat(Data{i,1}(1,65:68)))),'single');
Data2(i).H0_Points = hex2dec(cell2mat(Data{i,1}(1,135:136)));
Data2(i).R0_SectionName = convertCharsToStrings(char(hex2dec(Data{i,1}(1,137:138))));
Data2(i).R0_ScalingFactor = typecast(uint32(hex2dec(cell2mat(Data{i,1}(1,141:144)))),'single');
Data2(i).A2_SectionName = convertCharsToStrings(char(hex2dec(Data{i,1}(1,657:658))));
Data2(i).A2_AngleFirst = typecast(uint32(hex2dec(cell2mat(Data{i,1}(1,661:664)))),'single');
Data2(i).A2_ScalingFactor = typecast(uint32(hex2dec(cell2mat(Data{i,1}(1,665:668)))),'single');
Data2(i).I1_ScalingFactor = typecast(uint32(hex2dec(cell2mat(Data{i,1}(1,1209:1212)))),'single');
Data2(i).A2_AngleStep(1) = 0 ;
for j = 1 : Data2(i).H0_Points ;
factor = Data2(i).H0_SoundSpeed * Data2(i).R0_ScalingFactor / 2 ;
Data2(i).R0_Range(j) = factor * hex2dec(cell2mat(Data{i,1}(1, (2*j+143):(2*j+144))));
Data2(i).A2_AngleStepTemp(j) = hex2dec(cell2mat(Data{i,1}(1, (2*j+691):(2*j+692))));
Data2(i).A2_AngleStep(j) = Data2(i).A2_AngleFirst + (sum(Data2(i).A2_AngleStepTemp(1:(j)))*Data2(i).A2_ScalingFactor);
Data2(i).I1_Intensity(j) = Data2(i).I1_ScalingFactor * hex2dec(cell2mat(Data{i,1}(1, (2*j+1211):(2*j+1212))));
end
end
Data2 = rmfield(Data2, 'A2_AngleStepTemp' );
toc
It is not the most efficient way of reading it in but it works, however it is a bit slow.
I was wondering if anybody has some tips on how I can speed it up.
Thanks!
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!