How to fix " --> " arrow like Data as result of read file function?

조회 수: 37 (최근 30일)
Tyann Hardyn
Tyann Hardyn 2022년 4월 24일
편집: Voss 2022년 4월 25일
Hi,Community
this kinda new to me, because i rarely found this data as an output of read file function, like readmatrix, readtable, etc.... Iam just curious about how to handle these data that re annoyed me :
for emd_files = 1:emd_x
data_emd1 = detectImportOptions(fulls_emd{emd_files}, 'ReadVariableNames',false, 'Delimiter', ' ',...
'ThousandsSeparator', '', 'ConsecutiveDelimitersRule', 'join', 'FileType', 'delimitedtext', 'EmptyLineRule', 'skip', 'LeadingDelimitersRule', 'ignore');
data_emd1.VariableNames = ["Var1", "Var2", "Var3", "Var4", "Var5", "Var6", "Var7", "Var8", "Var9", "Var10", "Var11", "Var12", "Var13", "Var14", "Var15", "Var16"];
data_emd1.VariableTypes = ["string", "string", "string", "string", "string", "string", "string", "string", "string", "string", "string", "string", "string", "string", "string", "string"];
tabel_file_fixeds{emd_files} = readtable(fulls_emd{emd_files}, data_emd1);
k_array = str2double(table2array(tabel_file_fixeds{emd_files}(:, 1:8)));
a_array = str2double(table2array(tabel_file_fixeds{emd_files}(:, 9:16)));
end
when i execute tabel_file_fixeds{emd_files}, it show me an " error like" data like this :
"4" "3" "3" "3" "2" "2" "2" "1" "27" "15" "15" "15" "7" "7" "7" "3"
"4" "3" "4" "3" "2" "4" "4" "4" "27" "15" "27" "15" "7" "27" "27" "27"
"7" "7" "7" "7" "7" "6" "5" "4→140→140→140→140→140" "80" "48" "27" <missing> <missing> <missing> <missing> <missing>
"5" "4" "4" "3" "4" "5" "4" "4" "48" "27" "27" "15" "27" "48" "27" "27"
"5" "5" "4" "3" "3" "3" "3" "3" "48" "48" "27" "15" "15" "15" "15" "15"
I cannot fix the data in row 3 above that re actually is :
"7" "7" "7" "7" "7" "6" "5" "4" "80" "48" "27" "140" "140" "140" "140" "140"
Every row in the extracted data should be a 1 x 16 Data like the above.... But why the arrow ( -> ) data suddenly appears like that when handling 3 digits (hundred) or maybe more digit data (thousand, ten thousand, etc) , such as 140, 1400, etc....
Then, if the k_array data was executed by using that arrow data, it would become a NaN data... That so weird... Because i need these 140 data to be calculated...
Iam very grateful if someone can give me a solution to handle my problem here.... Thank you so much, everyone...
  댓글 수: 4
Star Strider
Star Strider 2022년 4월 25일
Using readmatrix produces:
M1 = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/976855/5K_Indeks_TUN.txt')
M1 = 31×16
3 3 3 3 2 2 2 2 15 15 15 15 7 7 7 7 3 3 3 3 3 3 2 2 15 15 15 15 15 15 7 7 4 2 3 2 2 2 2 1 27 7 15 7 7 7 7 3 3 4 4 3 2 2 3 3 15 27 27 15 7 7 15 15 3 3 3 3 2 2 2 2 15 15 15 15 7 7 7 7 3 4 4 3 3 3 3 3 15 27 27 15 15 15 15 15 2 3 3 1 0 2 2 2 7 15 15 3 0 7 7 7 4 1 3 2 3 3 1 2 27 3 15 7 15 15 3 7 4 2 3 3 3 3 3 2 27 7 15 15 15 15 15 7 4 3 3 3 3 3 3 3 27 15 15 15 15 15 15 15
Is this the result you want?
.
Tyann Hardyn
Tyann Hardyn 2022년 4월 25일
The error data was located in the very bottom of the file, Sir... When you find 3 digits data...

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

채택된 답변

Voss
Voss 2022년 4월 25일
편집: Voss 2022년 4월 25일
Those arrows represent tabs. In the file, the numbers are separated by a tab followed by one or two spaces, except before the 140's, which have no spaces, just tabs. Presumably that's because they're three-digit numbers and whatever program created this file used a tab followed by however many spaces are necessary to get the numbers to right-align.
When you read the file with readtable, you use space as the only delimiter (because that's what detectImportOptions tells you is the delimiter, perhaps). Using space as the delimiter when there are no spaces between numbers (as in the 140 140 140 ... sequence), causes those to run together. So instead use tab as the delimiter, or use tab and space both (since 'ConsecutiveDelimitersRule' is 'join'):
fulls_emd = {'5K_Indeks_TUN.txt'};
emd_files = 1;
data_emd1 = detectImportOptions(fulls_emd{emd_files}, ...
'ReadVariableNames',false, ...
'Delimiter', '\t',... % or {' ','\t'} (space and tab)
'ThousandsSeparator', '', ...
'ConsecutiveDelimitersRule', 'join', ...
'FileType', 'delimitedtext', ...
'EmptyLineRule', 'skip', ...
'LeadingDelimitersRule', 'ignore');
data_emd1.VariableNames = ["Var1", "Var2", "Var3", "Var4", "Var5", "Var6", "Var7", "Var8", "Var9", "Var10", "Var11", "Var12", "Var13", "Var14", "Var15", "Var16"];
data_emd1.VariableTypes = ["string", "string", "string", "string", "string", "string", "string", "string", "string", "string", "string", "string", "string", "string", "string", "string"];
tabel_file_fixeds{emd_files} = readtable(fulls_emd{emd_files}, data_emd1);
disp(tabel_file_fixeds{emd_files})
Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 Var9 Var10 Var11 Var12 Var13 Var14 Var15 Var16 ____ ____ ____ ____ ____ ____ ____ ____ _____ _____ _____ _____ _____ _____ _____ _____ "3" "3" "3" "3" "2" "2" "2" "2" "15" "15" "15" "15" "7" "7" "7" "7" "3" "3" "3" "3" "3" "3" "2" "2" "15" "15" "15" "15" "15" "15" "7" "7" "4" "2" "3" "2" "2" "2" "2" "1" "27" "7" "15" "7" "7" "7" "7" "3" "3" "4" "4" "3" "2" "2" "3" "3" "15" "27" "27" "15" "7" "7" "15" "15" "3" "3" "3" "3" "2" "2" "2" "2" "15" "15" "15" "15" "7" "7" "7" "7" "3" "4" "4" "3" "3" "3" "3" "3" "15" "27" "27" "15" "15" "15" "15" "15" "2" "3" "3" "1" "0" "2" "2" "2" "7" "15" "15" "3" "0" "7" "7" "7" "4" "1" "3" "2" "3" "3" "1" "2" "27" "3" "15" "7" "15" "15" "3" "7" "4" "2" "3" "3" "3" "3" "3" "2" "27" "7" "15" "15" "15" "15" "15" "7" "4" "3" "3" "3" "3" "3" "3" "3" "27" "15" "15" "15" "15" "15" "15" "15" "2" "2" "3" "3" "3" "4" "4" "4" "7" "7" "15" "15" "15" "27" "27" "27" "2" "2" "3" "3" "2" "2" "2" "2" "7" "7" "15" "15" "7" "7" "7" "7" "3" "3" "3" "3" "3" "3" "3" "3" "15" "15" "15" "15" "15" "15" "15" "15" "2" "4" "5" "5" "3" "2" "3" "3" "7" "27" "48" "48" "15" "7" "15" "15" "3" "5" "5" "4" "3" "3" "3" "3" "15" "48" "48" "27" "15" "15" "15" "15" "3" "3" "3" "3" "1" "1" "2" "1" "15" "15" "15" "15" "3" "3" "7" "3" "3" "3" "3" "3" "3" "2" "2" "2" "15" "15" "15" "15" "15" "7" "7" "7" "4" "5" "4" "1" "1" "2" "2" "1" "27" "48" "27" "3" "3" "7" "7" "3" "3" "4" "5" "3" "2" "3" "3" "3" "15" "27" "48" "15" "7" "15" "15" "15" "5" "5" "5" "5" "5" "4" "3" "4" "48" "48" "48" "48" "48" "27" "15" "27" "5" "5" "4" "3" "3" "3" "3" "3" "48" "48" "27" "15" "15" "15" "15" "15" "4" "3" "2" "4" "3" "3" "3" "3" "27" "15" "7" "27" "15" "15" "15" "15" "4" "4" "3" "3" "3" "3" "2" "3" "27" "27" "15" "15" "15" "15" "7" "15" "4" "3" "2" "3" "2" "2" "2" "3" "27" "15" "7" "15" "7" "7" "7" "15" "4" "4" "2" "1" "1" "1" "0" "1" "27" "27" "7" "3" "3" "3" "0" "3" "4" "3" "3" "3" "2" "2" "2" "1" "27" "15" "15" "15" "7" "7" "7" "3" "4" "3" "4" "3" "2" "4" "4" "4" "27" "15" "27" "15" "7" "27" "27" "27" "7" "7" "7" "7" "7" "6" "5" "4" "140" "140" "140" "140" "140" "80" "48" "27" "5" "4" "4" "3" "4" "5" "4" "4" "48" "27" "27" "15" "27" "48" "27" "27" "5" "5" "4" "3" "3" "3" "3" "3" "48" "48" "27" "15" "15" "15" "15" "15" "5" "4" "3" "3" "3" "0" "1" "1" "48" "27" "15" "15" "15" "0" "3" "3"
k_array = str2double(table2array(tabel_file_fixeds{emd_files}(:, 1:8)));
a_array = str2double(table2array(tabel_file_fixeds{emd_files}(:, 9:16)));
disp(k_array(end-6:end,:))
4 4 2 1 1 1 0 1 4 3 3 3 2 2 2 1 4 3 4 3 2 4 4 4 7 7 7 7 7 6 5 4 5 4 4 3 4 5 4 4 5 5 4 3 3 3 3 3 5 4 3 3 3 0 1 1
disp(a_array(end-6:end,:))
27 27 7 3 3 3 0 3 27 15 15 15 7 7 7 3 27 15 27 15 7 27 27 27 140 140 140 140 140 80 48 27 48 27 27 15 27 48 27 27 48 48 27 15 15 15 15 15 48 27 15 15 15 0 3 3
EDIT: or use readmatrix:
M = readmatrix(fulls_emd{emd_files});
k_array_new = M(:, 1:8);
a_array_new = M(:, 9:16);
isequal(k_array_new,k_array)
ans = logical
1
isequal(a_array_new,a_array)
ans = logical
1
  댓글 수: 2
Tyann Hardyn
Tyann Hardyn 2022년 4월 25일
편집: Tyann Hardyn 2022년 4월 25일
OMG.... Very Smooth !!! Thats Awesome and Great ! i never think that the error i got was come from determining the delimiter as just space not a TAB.... And your explanation is so Good Sir... Thank you so much... /.\ /.\ /.\
Voss
Voss 2022년 4월 25일
You're welcome!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by