How to create an array and then send it to arduino

2 views (last 30 days)
I have to create this array and the send each line to my arduino separetly
7 0 2 0 0 -1
8 6 3 9 0 -2
4 3 7 7 1 -3
4 4 6 7 7 -4
2 6 6 1 1 -5
4 9 3 5 2 -1
Matlab program
b = Bluetooth('HC-05', 1);
fopen(b);
x=[]; neg = 0;
for a=1:6
neg = neg - 1;
if (neg < -5)
neg = -1; %//wrap around
end
x = [x; [randi([0 9], 1, 5) neg]]; %//add new row of random numbers to x
fprintf(b,a);
disp(x);
end
disp('End');
disp(x);
The problem is that when I put fprintf function inside for it sends me only first line in correct form others all together. Output arduino
0 5 8 6 1 -1
03 54 89 61 18 --12
036 543 891 614 184 ---123
etc.
Disp in for function shows
7 0 2 0 0 -1
7 0 2 0 0 -1
8 6 3 9 0 -2
7 0 2 0 0 -1
8 6 3 9 0 -2
4 3 7 7 1 -3
Disp in the end show data in correct form.
End
7 0 2 0 0 -1
8 6 3 9 0 -2
4 3 7 7 1 -3
4 4 6 7 7 -4
2 6 6 1 1 -5
4 9 3 5 2 -1
So I think I got 2 options. Create array different way. Or in the end of the program split whole array and then send each line separetly. But I don't know how to do it. So can you guys help me I'm really desparete.

Answers (0)

Categories

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!