Problem using RESHAPE function
28 次查看(过去 30 天)
显示 更早的评论
I am trying to read the following text file:
1 24652U 96063A 96318.74847837 -.00000020 00000-0 00000+0 0 14
2 24652 003.9929 210.6007 7281127 177.7757 190.4436 02.27277888 06
1 24652U 96063A 96319.62211352 -.00000020 00000-0 00000+0 0 31
2 24652 003.9929 210.3183 7284735 178.4392 185.2995 02.27373269 12
1 24652U 96063A 96319.62351606 .00008082 00000-0 30835-2 0 24
2 24652 003.9764 210.1654 7280836 178.5436 186.6267 02.27380102 20
1 24652U 96063A 96319.62356237 .00009638 00000-0 38025-2 0 37
2 24652 003.9632 210.3512 7280110 178.4006 186.6625 02.27374993 25
1 24652U 96063A 96320.49676119 -.00000127 +00000-0 +10000-4 0 00072
2 24652 003.9626 209.9743 7275563 179.0821 184.3511 02.27899371000049
1 24652U 96063A 96320.50002676 .00012628 00000-0 46302-2 0 42
2 24652 003.9699 209.7044 7281567 179.3158 184.1451 02.27404164 41
1 24652U 96063A 96321.80711554 -.00000260 00000-0 10000-4 0 125
2 24652 003.9565 209.4880 7274507 180.0909 179.3623 02.27893681 73
1 24652U 96063A 96321.80729317 -.00002083 00000-0 -71075-3 0 80
2 24652 003.9582 209.4681 7275726 180.1221 179.5119 02.27890411 73
Using
fid=fopen('Arabsat 2B.txt');
A=textscan(fid,'%s');
Data=reshape(A{1}(1:end,:),9,[])';
fclose(fid);
format long g;
l1=Data(1:2:end,:);
l2=Data(2:2:end,:);
I was able to read another almost similar text file but when I try to run the code i get the error:
Error using reshape
Product of known dimensions, 9, not divisible into total number of elements, 56085.
Error in getTLE2 (line 10)
Data=reshape(A{1}(1:end,:),9,[])';
Kindly help that where am i going wrong.
0 个评论
采纳的回答
Razvan
2012-9-28
The problem is in the text file you try to import.
Line 10 (2 24652 003.9626 209.9743 7275563 179.0821 184.3511 02.27899371000049) has only 8 numbers...
更多回答(2 个)
Azzi Abdelmalek
2012-9-28
编辑:Azzi Abdelmalek
2012-9-28
complete with nan
fid=fopen('filee1.txt');
A=textscan(fid,'%s');
fclose(fid);
d=A{:}
n=rem(numel(d),9)
if n>0
d(end+1:end+9-n)=num2cell(nan)
end
Data=reshape(d (1:end,:),9,[])';
format long g;
l1=Data(1:2:end,:);
l2=Data(2:2:end,:);
0 个评论
Thomas
2012-9-28
编辑:Thomas
2012-9-28
For reshape to work the total number of elements should be divisible by the factor you are reshaping it by.
I n your case you have 56085 element and you are tring to reshpe it by factor 9 which will not work since 56085/9 is 6231.66
it is divible definitely by 5 so
Data=reshape(A{1}(1:end,:),5,[])'
should work
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Data Preparation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!