Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Thread Subject:
Problem with concatenating Arrays

Subject: Problem with concatenating Arrays

From: George-Laurentiu

Date: 1 Nov, 2013 17:26:05

Message: 1 of 1


I'm trying to do a real time plotting of the serial port incoming data

I used the following code

s = serial('COM10'); %assigns the object s to serial port
set(s, 'InputBufferSize', 256); %number of bytes in inout buffer
set(s, 'FlowControl', 'hardware');
set(s, 'BaudRate', 57600);
set(s, 'Parity', 'none');
set(s, 'DataBits', 8);
set(s, 'StopBit', 1);
set(s, 'Timeout',0.02);
prop(3)=(get(s, 'StopBit'));
prop(4)=(get(s, 'InputBufferSize'));
disp(['Port Setup Done!!',num2str(prop)]);
fopen(s) %opens the serial port
while(t < 200) %Runs for 200 cycles - if you cant see the symbol, it is "less than" sign. so while (t less than 200)
   a = fread(s); %reads the data from the serial port and stores it to the matrix a

   x(length(a)) =[x a]; % Merging the value to an array, this is not very computationaly effective, as the array size is dynamic.
                 %Consider pre allocation the size of the array to avoid this. But beware, You might loose some important
                  %data at the end!
   axis auto;
   grid on;
   disp([num2str(t),'iteration val= ',num2str(a)]);
   hold on;
   a=0; %Clear the buffer
fclose(s); %close the serial port

I'm receiving the following error message

Subscript indices must either be real positive integers or logicals.

Error in Real_time_daq2 (line 30)
   x(length(a)) =[x a]; % Merging the value to an array, this is not very
   computationaly effective, as the array size is dynamic.

If i try x =[x a]
I receive the following error message

Error using horzcat CAT arguments dimensions are not consistent.

How can i solve this problem ?

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us