I am new to matlab and have a sample data(shown on pic) with many values inside. I need to multiply each values with its different conversion coefficient. How can I do that?

조회 수: 1 (최근 30일)
CONV_COEFF = [0.0023394775; 0.0030514578; 0.0023394775; 0.0015258789; 0.0024414063; ...
0.0006103516; 0.0006103516; 0.0024414063; 0.0006103516; 0.0006103516; ...
0.0024414063; 0.0006103516; 0.0006103516; 0.0020345052; 0.0020345052; ...
1; 1; 0.0006103516; 0.00390625; 0.00390625; 0.00390625; 0.00390625; ...
1; 1; 1; 1; 1; 1; 0.00390625; 0.00390625; 0.00390625; 0.00390625; 0.00390625; ...
0.00390625; 0.00390625; 0.00390625; 1];
So for example, the value at 1 will need to multiply by 0.0023394775, value at 2 needs to mulitply by 0.0030514578, and so for.
I need to code to read this data from serial port and with the values I need to multiply each with its respective conversion coefficient. I need to run 100 samples.
Please help. :)

답변 (1개)

Sudhakar Shinde
Sudhakar Shinde 2020년 10월 6일
편집: Sudhakar Shinde 2020년 10월 6일
You could use 'serialport' and 'read' functions to read data from serial port.
for more info:
%Example reading 16 values
s = serialport("COM3",9600,"Timeout",5);
data = read(s,16,"uint32");
%Then use dot multiplication:
data.*CONV_COEFF
  댓글 수: 2
Wei Wei Gan
Wei Wei Gan 2020년 10월 6일
But i need to get 100 samples of that as the data inside will keep changing so do i just use loop? By the way how do u get "16,"uint32"
Wei Wei Gan
Wei Wei Gan 2020년 10월 6일
I also have a question. Why do i have missing data when I fscanf(s) the serial port? some times it reflect the values from 1-5 and sometimes 11-20.
s=serial('COM23','BaudRate',57600);
fopen(s);
fscanf(s)
fclose(s);
However, when I use the following code, it reflect all the values from 1-25 and 48.
s=serial('COM23','BaudRate',57600,'TimeOut',10,'Terminator','LF');
fopen(s);
received=fgets(s);
fscanf(s)
fclose(s);

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

카테고리

Help CenterFile Exchange에서 Variables에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by