Graphical representation of Ping
조회 수: 34 (최근 30일)
이전 댓글 표시
Hello ,
I hope anyone can answer this question!!
I want to represent ping result of an IP address using matlab in a graphical way .i am pinging the IP:192.168.1.1 using this command : [status, result] = dos('ping 192.168.1.1', '-echo') and getting the following :
>>result
result =
Pinging 192.168.1.1 with 32 bytes of data:
Reply from 192.168.1.1: bytes=32 time=2ms TTL=64
Reply from 192.168.1.1: bytes=32 time=4ms TTL=64
Reply from 192.168.1.1: bytes=32 time=10ms TTL=64
Reply from 192.168.1.1: bytes=32 time=8ms TTL=64
Ping statistics for 192.168.1.1: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Is there any way to take the time variable that is inside the result and plot a graph so the output of the graph looks close to this :
TIME
10ms| *
8ms| *
6ms|
4ms| *
2ms| *
-|-----------------------> PING NUMBER
1st 2nd 3rd 4th# Item one
# Item two
댓글 수: 4
답변 (2개)
Daniel Shub
2013년 3월 8일
편집: Daniel Shub
2013년 3월 8일
You can extract the time data with a regular expression
time = cellfun(@(y)(str2double(y{2})), regexp(result, '(time[=<])([\d]*\.[\d]*)', 'tokens'))
댓글 수: 8
Walter Roberson
2013년 3월 9일
Tyler, Daniel's expression
time = cellfun(@(y)(str2double(y{2})), regexp(result, '(time[=<])([\d]*\.[\d]*)', 'tokens'))
is like writing
time = cellfun( @Convert_To_Number, regexp(result, '(time[=<])([\d]*\.[\d]*)', 'tokens') );
function result = Convert_To_Number( y )
result = str2double( y{2} );
end
That is, "y" is just the name of the variable used temporarily to perform the function.
Daniel Shub
2013년 3월 9일
My regexp is wrong. I don't use Windows so my ping returns something slightly different from yours. I didn't check to compare. My ping returns time as 20.2ms while yours does not have the decimal. The regexp looks for the word "time" followed by either = or <, and then followed by and number of digits (\d) a decimal point (\.) and en any number of digits. Since your ping does not return a decimal point just remove the \.[\d]* from the regexp. The y is just a fancy way of making cell fun work. Focus on getting regexp to return something meaningful.
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!