how can I find a short int array from a long int array

2 次查看(过去 30 天)
Now I have a long int array including some short array such beginning with 55 and ending 00, whose length was 10, but the contents between 55 and 00 could not be recognized for they were send from serial port. How could I extract those short arrays from the long array? Thanks!
  4 个评论
Walter Roberson
Walter Roberson 2017-4-30
How are you doing the reading from the text file? The details might matter.
wenlong
wenlong 2017-4-30
I had a stm32f0, it just send datas from serial port to pc, I did not use any protocol

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2017-4-30
as_short = typecast(YourLongArray, 'uint16');
sub_pos = find(as_short(1:end-9) == 55 & as_short(10:end) == 0);
short_array = as_short(sub_pos:sub_pos+9);
  8 个评论
Walter Roberson
Walter Roberson 2017-5-3
You would normally need to write a protocol that triggers the mcu to send data, instead of just immediately sending it.
Perhaps you were thinking that when the MCU opens its serial port that the MCU would then wait untl MATLAB opens the serial port on its side before the MCU would proceed to send the data. It is possible to program serial ports that way, but it is not typically done on instruments.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 String Parsing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by