Effacer les filtres
Effacer les filtres

Can someone help me? Am getting the following error.

1 vue (au cours des 30 derniers jours)
John Amakali
John Amakali le 8 Mai 2018
Error using vertcat Dimensions of matrices being concatenated are not consistent. Error in GUI>pushbutton1_Callback (line 144)
part of the code: while(i<=numberOfDatas)
q = fscanf(s, '%f');
Tdata=[Tdata(2:end), q]; %Get the data from the serial object
set(M,'Zdata',[Tdata; zeroIndex],'Cdata',[Tdata; Tdata]);
drawnow;
c=round(clock);
data_sensor{1,1}=strcat(num2str(c(4)),...
':',num2str(c(5)),':',num2str(c(6))); %Current Time no. data conversion to string for Excel export
data_sensor{1,2}=q;
d=[d; data_sensor]; %Append new data to previous data matrix
i=i+1; %Increment the counter
end
if true
% code
end
  2 commentaires
Rik
Rik le 8 Mai 2018
The answer is in the error text: you are concatenating several variables in this code snippet, and one of those don't fit. Use the debugger to stop on error (you can type dbstop if error to enable it). Then you can see the sizes of the arrays you're trying to concatenate and see how those don't fit. Then you can modify your code accordingly.
John Amakali
John Amakali le 8 Mai 2018
I tried but i couldnt , can i send you my whole code then you see where i went wrong.

Connectez-vous pour commenter.

Réponses (3)

KSSV
KSSV le 8 Mai 2018
YOu cannot append two arrays with different dimensions....check below:
[rand(1,3) rand(4,1)] % it throws error.
[rand(1,3) rand(1,4)] % no error
[rand(3,1) ; rand(4,1)] % no error
You check for such a situation in your code.
  1 commentaire
John Amakali
John Amakali le 8 Mai 2018
line 144 = set(M,'Zdata',[Tdata; zeroIndex],'Cdata',[Tdata; Tdata]);
they are first pointing at that line.

Connectez-vous pour commenter.


John Amakali
John Amakali le 8 Mai 2018
Can you please help me.. how about you just go through my code and see where i went wrong.
  3 commentaires
John Amakali
John Amakali le 8 Mai 2018
line 144 = set(M,'Zdata',[Tdata; zeroIndex],'Cdata',[Tdata; Tdata]);
they are first pointing at that line.
Dennis
Dennis le 8 Mai 2018
I do not know what size Tdata or zeroIndex have. I could guess that they do not have the same length so [Tdata;zeroIndex] throws out an error. But without information about Tdata,q and zeroIndex its just a guess.

Connectez-vous pour commenter.


John Amakali
John Amakali le 8 Mai 2018
am actually collecting a sample of data=500 please the full function of the temperature button.
%%TEMPRATURE % --- Executes on button press in pushbutton1.%%TEMPRATURE function pushbutton1_Callback(hObject, eventdata, handles)
s = serial('COM5'); %create serial object set(s,'BaudRate', 9600); %set baud rate set(s,'DataBits', 8); set(s,'StopBits', 1); fopen(s); %open port for communication s.ReadAsyncMode = 'continuous'; %enable continuous data read operation fwrite(s,'T'); %transmit 'T' to receive temperature
% Various variables numberOfDatas = 500; %no of sensor data to be ploted Temp = zeros(1, numberOfDatas); %array of zeroes i = 1;
%-------Excel File Declarations %delete 'xbee1.xlsx'; %delete previous file filename='C:\Users\John N A\Documents'; %create new file sheet=1; %excel sheet no cell_ascii=66; %excel cell Alphabet ASCII 66='B'
readasync(s); %synchronous reading
%Data Plot Specifications h=figure(1); if(~exist('myAxes','var')) %cheak if declaration already exists buf_len=500; %no. plots to be shown at a time on display index=1:buf_len; zeroIndex=zeros(size(index)); %array of zeroes Tdata=zeroIndex; limits=[15 50]; %colorbar range
myAxes = axes('XLim',[0 buf_len],'Ylim',[0 0.1],'ZLim',limits,'CLim',limits);
view(0,0); %Rotation and height of plot
grid on;
M=surface(index,[0,0],[Tdata; zeroIndex],[Tdata; Tdata]);%surface plot specs
set(M,'EdgeColor','flat','FaceColor','flat', 'parent',myAxes)
colorbar
title('Real-Time Temp Readings, \circC'); %plot title
xlabel('Samples');
zlabel('Temprature (\circC)');
set(h,'Position',[200 200 890 660]); %plot position on screen
drawnow; %force matlab to draw
end
d=cell(1,2); %data matrix dimension declaration d{1,1}='Time'; d{1,2}='Temprature';
while(i<=numberOfDatas)
q = fscanf(s, '%f');
Tdata=[Tdata(2:end), q]; %Get the data from the serial object
set(M,'Zdata',[Tdata; zeroIndex],'Cdata',[Tdata; Tdata]);
drawnow;
c=round(clock);
data_sensor{1,1}=strcat(num2str(c(4)),...
':',num2str(c(5)),':',num2str(c(6))); %Current Time no. data conversion to string for Excel export
data_sensor{1,2}=q;
d=[d; data_sensor]; %Append new data to previous data matrix
i=i+1; %Increment the counter
end
xlRange = sprintf('%c%i',cell_ascii,2); %excel range xlswrite(filename,d,sheet,xlRange); %command to write data to excel cell_ascii=cell_ascii+2; %increment cell accii for humidity plot clear d; %clear data register after logging
stopasync(s); %stop sync for serial object fclose(s); %close COM port delete(s); %delete Serial object clear s;
see where you can help me please

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by