In the data set, i have one specific column which has 12 characters.It is a alphanumeric column.(pls see the attachment). Alphanumeric column sequence should be 0,1,2,3,....9,a,b,c,...f. But within the data set it differs(eg:3rd value in the file). I want to detect that value. (PS: since it has 12 characters, i want to first detect: first 4 characters(from the left) and if that's true then detect the last 4 digits). Any suggestions.

 채택된 답변

Michael Haderlein
Michael Haderlein 2015년 2월 4일
편집: Michael Haderlein 2015년 2월 4일

1 개 추천

Why do you want to detect first 4 characters from the left and then the last 4 digits? My suggestion is:
fid=fopen('test.txt');
data=textscan(fid,'%s');
fclose(fid);
diff(cellfun(@hex2dec,data{1}))>1
This will always be false except of the step ...67 ...69
Edit: If you want to get the respective value which is too large:
data{1}([false;diff(cellfun(@hex2dec,data{1}))>1])
ans =
'03ff00000169'

댓글 수: 3

Chathu
Chathu 2015년 2월 4일
Thank you so much for your response Michael. Your code works well if there is a numerical jump ONLY.(as inquired in my question)
(i am sorry i forgot to mention) But there is a possibility that alphabetic values can get skipped.That's why i thought to split the 12 characters: as first 4 and last 4.
(1) Instead of hex@dec, can i use dec2hex? ( eg: @hex2dec,data{1}))>1 )
(2)But this time it cannot be 1,correct? (because we are considering alphabetic characters as well. Suppose alphabetic characters have been skipped. How to overcome this issue?
I don't understand the problem. Do you mean that after 03ff0000ffff the next value would be 040000000000? Or would the next value be 03ff00010000?
Maybe a short explanation about my code: I first convert all the data (e.g. 03ff00000169) from hexadecimal to decimal: hex2dec('03ff00000169')=4393751544169
Then, I check the difference of the values. If it's larger than 1 (i.e. at least one value is missing), the too large value will be displayed. In case 03ffffffffff is followed by 040e00000000 (instead of 040000000000), the difference is also >1 and the respective value will be displayed. Is that what you want?
Chathu
Chathu 2015년 2월 5일
Michael-i got your point and clarified my doubt. Thank you so much for your explanation. Appreciate it.

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

질문:

2015년 2월 4일

댓글:

2015년 2월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by